How to Get country name from country code in Magento 2?Magento 2 - Get country in billing addressMagento 2.2.4 Change Country NamesMagento 2.3.0 Get Country NameGet Store/Website by Language/Countrymagento 2 : Get country from IP addressHow to customize Locale country codeGet the country code of website userUpdating country name in magento 2Magento 2.2.4 Change Country NamesMagento 2 :Get country code from Country NameMagento 2.3.0 Get Country NameHow to get country dial code for telephone number in Magento 2?

Assassin's bullet with mercury

Forgetting the musical notes while performing in concert

Why can't we play rap on piano?

Can compressed videos be decoded back to their uncompresed original format?

How did the Super Star Destroyer Executor get destroyed exactly?

Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?

Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?

Bullying boss launched a smear campaign and made me unemployable

Is it logically or scientifically possible to artificially send energy to the body?

Which is the best way to check return result?

Determining Impedance With An Antenna Analyzer

What is the most common color to indicate the input-field is disabled?

Can I run a new neutral wire to repair a broken circuit?

Plagiarism or not?

Expand and Contract

iPad being using in wall mount battery swollen

Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?

Why are the 737's rear doors unusable in a water landing?

How do I gain back my faith in my PhD degree?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Personal Teleportation: From Rags to Riches

What exploit Are these user agents trying to use?

Unlock My Phone! February 2018

Mathematica command that allows it to read my intentions



How to Get country name from country code in Magento 2?


Magento 2 - Get country in billing addressMagento 2.2.4 Change Country NamesMagento 2.3.0 Get Country NameGet Store/Website by Language/Countrymagento 2 : Get country from IP addressHow to customize Locale country codeGet the country code of website userUpdating country name in magento 2Magento 2.2.4 Change Country NamesMagento 2 :Get country code from Country NameMagento 2.3.0 Get Country NameHow to get country dial code for telephone number in Magento 2?













8















i want to get country name from country code, i got the country code from the data order like this :



$data = $order->getShippingAddress()->getData();
$countryCode = $data['country_id'];
echo $countryCode;


it will print 'US' or any other country code, is there a way to get the country name from this country code?










share|improve this question
























  • Have you check code for get country name?

    – Rakesh Jesadiya
    Feb 13 '17 at 5:40















8















i want to get country name from country code, i got the country code from the data order like this :



$data = $order->getShippingAddress()->getData();
$countryCode = $data['country_id'];
echo $countryCode;


it will print 'US' or any other country code, is there a way to get the country name from this country code?










share|improve this question
























  • Have you check code for get country name?

    – Rakesh Jesadiya
    Feb 13 '17 at 5:40













8












8








8


1






i want to get country name from country code, i got the country code from the data order like this :



$data = $order->getShippingAddress()->getData();
$countryCode = $data['country_id'];
echo $countryCode;


it will print 'US' or any other country code, is there a way to get the country name from this country code?










share|improve this question
















i want to get country name from country code, i got the country code from the data order like this :



$data = $order->getShippingAddress()->getData();
$countryCode = $data['country_id'];
echo $countryCode;


it will print 'US' or any other country code, is there a way to get the country name from this country code?







magento2 model country-regions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 '17 at 4:49









Manthan Dave

7,97621539




7,97621539










asked Feb 13 '17 at 4:49









simple guysimple guy

1,07421542




1,07421542












  • Have you check code for get country name?

    – Rakesh Jesadiya
    Feb 13 '17 at 5:40

















  • Have you check code for get country name?

    – Rakesh Jesadiya
    Feb 13 '17 at 5:40
















Have you check code for get country name?

– Rakesh Jesadiya
Feb 13 '17 at 5:40





Have you check code for get country name?

– Rakesh Jesadiya
Feb 13 '17 at 5:40










4 Answers
4






active

oldest

votes


















21














Create Block file,



 public function __construct(
MagentoDirectoryModelCountryFactory $countryFactory
)
$this->_countryFactory = $countryFactory;


public function getCountryname($countryCode)
$country = $this->_countryFactory->create()->loadByCode($countryCode);
return $country->getName();



Call from phtml file,



echo $block->getCountryname($countryCode);





share|improve this answer




















  • 1





    Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

    – Eirik
    May 6 '17 at 18:16











  • Is it possible to get country code from country name?

    – Vindhuja
    Nov 29 '18 at 6:20











  • @Vindhuja Check rakeshjesadiya.com/…

    – Rakesh Jesadiya
    Nov 29 '18 at 6:29


















3














We can use MagentoDirectoryApiCountryInformationAcquirerInterface to get the country info:



/** @var MagentoDirectoryApiCountryInformationAcquirerInterface $country */

/** @var MagentoDirectoryApiDataCountryInformationInterface $data */
$data = $country->getCountryInfo($data['country_id']);
$data->getFullNameEnglish();
$data->getFullNameLocale();


See more here about the returned values: MagentoDirectoryApiDataCountryInformationInterface






share|improve this answer






























    0














    Check the given model of country and its methods:



    /**
    *
    * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
    * @param MagentoDirectoryModelCountryFactory $countryFactory
    */
    public function __construct(
    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
    MagentoDirectoryModelCountryFactory $countryFactory
    )
    $this->scopeConfig = $scopeConfig;
    $this->countryFactory = $countryFactory;



    One of the method it provides is $this->countryFactory->create()->getName(); .You can use the model factory based on your requirements.






    share|improve this answer
































      -2














      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $allowerdContries = $objectManager->get('MagentoDirectoryModelAllowedCountries')->getAllowedCountries() ;
      $countryFactory = $objectManager->get('MagentoDirectoryModelCountryFactory');
      //echo "<pre>"; print_r($allowerdContries);

      $countries = array();
      foreach($allowerdContries as $countryCode)

      if($countryCode)


      $data = $countryFactory->create()->loadByCode($countryCode);
      $countries[$countryCode] = $data->getName();







      share|improve this answer

























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "479"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159494%2fhow-to-get-country-name-from-country-code-in-magento-2%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        21














        Create Block file,



         public function __construct(
        MagentoDirectoryModelCountryFactory $countryFactory
        )
        $this->_countryFactory = $countryFactory;


        public function getCountryname($countryCode)
        $country = $this->_countryFactory->create()->loadByCode($countryCode);
        return $country->getName();



        Call from phtml file,



        echo $block->getCountryname($countryCode);





        share|improve this answer




















        • 1





          Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

          – Eirik
          May 6 '17 at 18:16











        • Is it possible to get country code from country name?

          – Vindhuja
          Nov 29 '18 at 6:20











        • @Vindhuja Check rakeshjesadiya.com/…

          – Rakesh Jesadiya
          Nov 29 '18 at 6:29















        21














        Create Block file,



         public function __construct(
        MagentoDirectoryModelCountryFactory $countryFactory
        )
        $this->_countryFactory = $countryFactory;


        public function getCountryname($countryCode)
        $country = $this->_countryFactory->create()->loadByCode($countryCode);
        return $country->getName();



        Call from phtml file,



        echo $block->getCountryname($countryCode);





        share|improve this answer




















        • 1





          Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

          – Eirik
          May 6 '17 at 18:16











        • Is it possible to get country code from country name?

          – Vindhuja
          Nov 29 '18 at 6:20











        • @Vindhuja Check rakeshjesadiya.com/…

          – Rakesh Jesadiya
          Nov 29 '18 at 6:29













        21












        21








        21







        Create Block file,



         public function __construct(
        MagentoDirectoryModelCountryFactory $countryFactory
        )
        $this->_countryFactory = $countryFactory;


        public function getCountryname($countryCode)
        $country = $this->_countryFactory->create()->loadByCode($countryCode);
        return $country->getName();



        Call from phtml file,



        echo $block->getCountryname($countryCode);





        share|improve this answer















        Create Block file,



         public function __construct(
        MagentoDirectoryModelCountryFactory $countryFactory
        )
        $this->_countryFactory = $countryFactory;


        public function getCountryname($countryCode)
        $country = $this->_countryFactory->create()->loadByCode($countryCode);
        return $country->getName();



        Call from phtml file,



        echo $block->getCountryname($countryCode);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 mins ago









        Community

        1




        1










        answered Feb 13 '17 at 4:56









        Rakesh JesadiyaRakesh Jesadiya

        30.1k1576124




        30.1k1576124







        • 1





          Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

          – Eirik
          May 6 '17 at 18:16











        • Is it possible to get country code from country name?

          – Vindhuja
          Nov 29 '18 at 6:20











        • @Vindhuja Check rakeshjesadiya.com/…

          – Rakesh Jesadiya
          Nov 29 '18 at 6:29












        • 1





          Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

          – Eirik
          May 6 '17 at 18:16











        • Is it possible to get country code from country name?

          – Vindhuja
          Nov 29 '18 at 6:20











        • @Vindhuja Check rakeshjesadiya.com/…

          – Rakesh Jesadiya
          Nov 29 '18 at 6:29







        1




        1





        Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

        – Eirik
        May 6 '17 at 18:16





        Correct except you are missing a semi colon after $country = $this->_countryFactory->create()->loadByCode($countryCode) it should be $country = $this->_countryFactory->create()->loadByCode($countryCode);

        – Eirik
        May 6 '17 at 18:16













        Is it possible to get country code from country name?

        – Vindhuja
        Nov 29 '18 at 6:20





        Is it possible to get country code from country name?

        – Vindhuja
        Nov 29 '18 at 6:20













        @Vindhuja Check rakeshjesadiya.com/…

        – Rakesh Jesadiya
        Nov 29 '18 at 6:29





        @Vindhuja Check rakeshjesadiya.com/…

        – Rakesh Jesadiya
        Nov 29 '18 at 6:29













        3














        We can use MagentoDirectoryApiCountryInformationAcquirerInterface to get the country info:



        /** @var MagentoDirectoryApiCountryInformationAcquirerInterface $country */

        /** @var MagentoDirectoryApiDataCountryInformationInterface $data */
        $data = $country->getCountryInfo($data['country_id']);
        $data->getFullNameEnglish();
        $data->getFullNameLocale();


        See more here about the returned values: MagentoDirectoryApiDataCountryInformationInterface






        share|improve this answer



























          3














          We can use MagentoDirectoryApiCountryInformationAcquirerInterface to get the country info:



          /** @var MagentoDirectoryApiCountryInformationAcquirerInterface $country */

          /** @var MagentoDirectoryApiDataCountryInformationInterface $data */
          $data = $country->getCountryInfo($data['country_id']);
          $data->getFullNameEnglish();
          $data->getFullNameLocale();


          See more here about the returned values: MagentoDirectoryApiDataCountryInformationInterface






          share|improve this answer

























            3












            3








            3







            We can use MagentoDirectoryApiCountryInformationAcquirerInterface to get the country info:



            /** @var MagentoDirectoryApiCountryInformationAcquirerInterface $country */

            /** @var MagentoDirectoryApiDataCountryInformationInterface $data */
            $data = $country->getCountryInfo($data['country_id']);
            $data->getFullNameEnglish();
            $data->getFullNameLocale();


            See more here about the returned values: MagentoDirectoryApiDataCountryInformationInterface






            share|improve this answer













            We can use MagentoDirectoryApiCountryInformationAcquirerInterface to get the country info:



            /** @var MagentoDirectoryApiCountryInformationAcquirerInterface $country */

            /** @var MagentoDirectoryApiDataCountryInformationInterface $data */
            $data = $country->getCountryInfo($data['country_id']);
            $data->getFullNameEnglish();
            $data->getFullNameLocale();


            See more here about the returned values: MagentoDirectoryApiDataCountryInformationInterface







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 13 '17 at 6:24









            Khoa TruongDinhKhoa TruongDinh

            22k64187




            22k64187





















                0














                Check the given model of country and its methods:



                /**
                *
                * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
                * @param MagentoDirectoryModelCountryFactory $countryFactory
                */
                public function __construct(
                MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
                MagentoDirectoryModelCountryFactory $countryFactory
                )
                $this->scopeConfig = $scopeConfig;
                $this->countryFactory = $countryFactory;



                One of the method it provides is $this->countryFactory->create()->getName(); .You can use the model factory based on your requirements.






                share|improve this answer





























                  0














                  Check the given model of country and its methods:



                  /**
                  *
                  * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
                  * @param MagentoDirectoryModelCountryFactory $countryFactory
                  */
                  public function __construct(
                  MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
                  MagentoDirectoryModelCountryFactory $countryFactory
                  )
                  $this->scopeConfig = $scopeConfig;
                  $this->countryFactory = $countryFactory;



                  One of the method it provides is $this->countryFactory->create()->getName(); .You can use the model factory based on your requirements.






                  share|improve this answer



























                    0












                    0








                    0







                    Check the given model of country and its methods:



                    /**
                    *
                    * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
                    * @param MagentoDirectoryModelCountryFactory $countryFactory
                    */
                    public function __construct(
                    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
                    MagentoDirectoryModelCountryFactory $countryFactory
                    )
                    $this->scopeConfig = $scopeConfig;
                    $this->countryFactory = $countryFactory;



                    One of the method it provides is $this->countryFactory->create()->getName(); .You can use the model factory based on your requirements.






                    share|improve this answer















                    Check the given model of country and its methods:



                    /**
                    *
                    * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
                    * @param MagentoDirectoryModelCountryFactory $countryFactory
                    */
                    public function __construct(
                    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
                    MagentoDirectoryModelCountryFactory $countryFactory
                    )
                    $this->scopeConfig = $scopeConfig;
                    $this->countryFactory = $countryFactory;



                    One of the method it provides is $this->countryFactory->create()->getName(); .You can use the model factory based on your requirements.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 2 '18 at 12:16









                    Sourabh Kumar Sharma

                    671316




                    671316










                    answered Feb 13 '17 at 4:56









                    Sanjay ChaudharySanjay Chaudhary

                    385217




                    385217





















                        -2














                        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                        $allowerdContries = $objectManager->get('MagentoDirectoryModelAllowedCountries')->getAllowedCountries() ;
                        $countryFactory = $objectManager->get('MagentoDirectoryModelCountryFactory');
                        //echo "<pre>"; print_r($allowerdContries);

                        $countries = array();
                        foreach($allowerdContries as $countryCode)

                        if($countryCode)


                        $data = $countryFactory->create()->loadByCode($countryCode);
                        $countries[$countryCode] = $data->getName();







                        share|improve this answer





























                          -2














                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $allowerdContries = $objectManager->get('MagentoDirectoryModelAllowedCountries')->getAllowedCountries() ;
                          $countryFactory = $objectManager->get('MagentoDirectoryModelCountryFactory');
                          //echo "<pre>"; print_r($allowerdContries);

                          $countries = array();
                          foreach($allowerdContries as $countryCode)

                          if($countryCode)


                          $data = $countryFactory->create()->loadByCode($countryCode);
                          $countries[$countryCode] = $data->getName();







                          share|improve this answer



























                            -2












                            -2








                            -2







                            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                            $allowerdContries = $objectManager->get('MagentoDirectoryModelAllowedCountries')->getAllowedCountries() ;
                            $countryFactory = $objectManager->get('MagentoDirectoryModelCountryFactory');
                            //echo "<pre>"; print_r($allowerdContries);

                            $countries = array();
                            foreach($allowerdContries as $countryCode)

                            if($countryCode)


                            $data = $countryFactory->create()->loadByCode($countryCode);
                            $countries[$countryCode] = $data->getName();







                            share|improve this answer















                            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                            $allowerdContries = $objectManager->get('MagentoDirectoryModelAllowedCountries')->getAllowedCountries() ;
                            $countryFactory = $objectManager->get('MagentoDirectoryModelCountryFactory');
                            //echo "<pre>"; print_r($allowerdContries);

                            $countries = array();
                            foreach($allowerdContries as $countryCode)

                            if($countryCode)


                            $data = $countryFactory->create()->loadByCode($countryCode);
                            $countries[$countryCode] = $data->getName();








                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 14 at 10:07









                            Khushbu

                            9010




                            9010










                            answered Feb 14 at 9:39









                            Jaykumar RJaykumar R

                            172




                            172



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Magento Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159494%2fhow-to-get-country-name-from-country-code-in-magento-2%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

                                Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

                                Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko