Magento 1.9 – How to Get Country ID from Country Name

countriesdirectorymagento-1.9

I want to get country_id from the country name in Magento, Please suggest how can I achieve this.
I found these database tables but they are not helpful:

  • directory_country
  • directory_country_region
  • directory_country_region_name

Best Answer

You can use below code for that

$countryName = 'your country name';
$countryId = '';
$countryCollection = Mage::getModel('directory/country')->getCollection();
foreach ($countryCollection as $country) {
    if ($countryName == $country->getName()) {
        $countryId = $country->getCountryId();
        break;
    }
}
$countryCollection = null;
print_r($countryId);
Related Topic