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.

7 thoughts on “Get List of Countries in Magento

  1. 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,

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

      $allowCountries = explode(',', (string)Mage::getStoreConfig('general/country/allow', $store)); 
      
  2. 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.”;

    }
    ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top