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.



2 Responses to “Get List of Countries in Magento”

  1. 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.”;

    }
    ?>

  2. Xiang.Liu says:

    great !

Leave a Reply

top