Author - Robert Popovic

Founder and Technical Director of LERO9, a web agency specializing in Magento and WordPress design and development.

I launched Magebase in April, 2010 and am its editor and contributor. My main topics of interest are Magento development, customization and how to get the most out of Magento with the least amount of headache.

More Info » Follow me on Twitter »

Reader Comments (27)

  1. Andy
    October 6, 2010 at 9:13 pm /

    Very nice article, Robert! I wish I could find it before.
    We’ve been trying to implement the same feature for our client’s store but then found a nice solution, very similar to yours. Store and currency auto switcher extensions by mageworx

  2. nathan
    December 11, 2010 at 3:48 am /

    This is AWESOME.. I don’t need to pay for an extension now… man you are great.

    I’ll make all my trademe related code public too soon when it’s done..

    So everyone are free to upload to trademe programtically…


  3. Anonymous
    December 21, 2010 at 7:40 am /

    […] […]

  4. Jo
    March 29, 2011 at 9:06 am /

    Thank you!

  5. nathan chen
    March 29, 2011 at 11:28 pm /

    oh this is awesome…. awesome…

  6. Setting default values based on GeoIP data – Tutorials – Magebase

    […] up on Robert’s article How To Set Default Store Currency Based On Visitor Country In Magento I wanted to take the concept in a slightly different direction: Firstly I wanted to have an […]

  7. kannankrp
    September 6, 2011 at 9:53 pm /

    Hi Robert,

    Thank you very much your useful article.

    Thanks and Regards,

    Kannan P

  8. Palanikumar
    September 7, 2011 at 8:00 pm /

    Hi Robert,

    I tried your module. But am getting below fatal error
    “Fatal error: Call to undefined function geoip_country_code_by_name()”.

    Magento talks

  9. Kannankrp
    September 7, 2011 at 9:04 pm /

    Hi Palani,

    Please check installation properly and also check php.ini file and php-geoip extension.

    Please check below mention URL:

    Thanks and regards,


  10. will
    January 10, 2012 at 5:28 pm /

    great module, and great explanation. Any idea how to switch between magento websites instead of currencies?

    happy new year

  11. will
    January 11, 2012 at 10:21 am /

    thanks for the really quick reply, I have a switcher already built a bit differently as below. Sorry for confusion but I am trying to create an automatic website switcher as you said like in Stores > websites. I have a few different “magento websites” which I want to switch between based on what IP it is, I tried to extend website.php in a similar way to you have extended store.php by using function getDefaultStore() but this function is looking to return a magento object Mage_Core_Model_Store so not sure if this is the right way to do it. many thanks for the help

    						$websites = Mage::getModel('core/website')->getCollection();
    						$i = 0;
    						foreach($websites as $website)
    						    $default_store = $website->getDefaultStore();
    						    $url_obj = new Mage_Core_Model_Url();
    						    $default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
    						    <option name="<?php  $i++; echo $i; ?>"
    						    <?php if(strstr($this->helper('core/url')->getCurrentUrl(), $default_store_path)): ?>selected="selected"<?php endif; ?> value="<?php echo $default_store_path ?>"><?php echo $website->getName(); ?></option>
  12. will
    January 11, 2012 at 12:15 pm /

    thanks again but it is not the template I’m trying to change rather the way the ip directs the user to the right site in you function

    public function getDefaultCurrencyCode()

    the currency code is pulled from the geoip data and returned back to the store to dislay the currency code.
    I want to use the currency code from the geoip data to set what website the user is on. Maybe I am not doing this the right way, I had a search throught the code and couldn’t find any where any function like getDefaultWebsite so have been trying it with

  13. Geoff
    June 21, 2012 at 5:30 am /

    I don’t mean to sound stupid but what web proxies did you use to test this. The one’s I’m googling don’t seem to work well

  14. Antaryami
    July 29, 2012 at 3:52 am /

    will it work with magento 1.6 and if possible can you provide the free modules

  15. Jaya
    September 12, 2012 at 10:43 pm /


    I have used your code ,thank you so much and great work done….

    But if i have some special price ,its showing in default currency not in detected currency code .

    please suggest me regarding this….waiting for…

    Thanks in advance….

  16. Remco
    October 4, 2012 at 4:32 am /

    Hi Robert,

    Thanks for the great tutorial.
    I was trying to install it on my Magento 1.5.1 installation, but it doesn’t work.

    The website stops loading when it want’s to show the Currency selector.

    Do you have any idea how to solve this problem?

  17. Richard Maurice
    May 28, 2014 at 7:49 am /

    Hi Robert, this is a great article.

    is there a way to pre-select the currency of the shopper in an Enterprise Magento with FPC active?

    It seems that the first time Magento loads the pre-selected currency based on the IP of the shopper doesn’t works, it starts working as soon as the shopper start browsing in the other links of the store. It just doesn’t work the first time the page loads.

    is there any way to hole-punch the product prices?


  18. Stephen
    December 2, 2014 at 11:03 pm /

    You have not accounted for the ability of the user to change to their required currency if the geoip lookup is incorrect.
    In this case I feel the best thing to do it have a cookie with the following variables:

    geo_country_test = true/false
    selected_country = true/false

    is whether the geo country has been done on user


    is actual country of user


    is whether user has changed currency manually

  19. Mukesh
    January 3, 2015 at 2:29 am /

    Hi Robert,

    Thanks for the tutorial.

    I have created a FREE “Auto Currency Switcher” extension for Magento which uses Max Mind’s GeoIP.dat file and Max Mind’s GeoIP PHP API.

    Here is the extension link:

    Thanks and Regards,

  20. Selva
    October 20, 2015 at 9:21 pm /

    Good article with guidelines. Awesome!!!.



Add a Comment & Join the Discussion

Insert small snippets of code by using [code]{your_code_here}[/code]
For larger code blocks please use and paste your link.

You may also use the following HTML in your comment: <a href="" title=""> <abbr title="">
<acronym title=""> <blockquote cite=""> <cite> <em> <strike> <strong>