search
top

Get List of Countries in Magento

I have explained the method below for getting the list of Country which we see in Magento. site checkout page.

Below code to be written in Block file in a function (you can even write the code in template file).

<?php

    $collection = Mage::getModel('directory/country')->getCollection();    
    foreach ($collection as $country) 
    {
        $cid = $country->getId();
	$cname = $country->getName();
        echo 'Country ID -> '.$cid.' Country Name -> '.$cname.'<br/>';
		                      
    }
?>

Hope this is helpful to many of you.

6 Responses to “Get List of Countries in Magento”

  1. Rao says:

    what if i want only the allowed countries out of this collection? is this possible? or is there any other way for doing it?

    thanks,

    • Pragnesh says:

      Its configured from admin end (Admin > System > configuration > General),

      $allowCountries = explode(',', (string)Mage::getStoreConfig('general/country/allow', $store)); 
      
  2. kea says:

    great, thanks…

  3. Boboy says:

    Thanks a lot !

  4. GregC says:

    Thanks! Here’s the code to turn this into a standalone php script

    getCollection();
    foreach ($collection as $country)
    {
    $cid = $country->getId();
    $cname = $country->getName();
    echo ‘Country ID -> ‘.$cid.’ Country Name -> ‘.$cname.”;

    }
    ?>

  5. Xiang.Liu says:

    great !

Leave a Reply

top