Skip to content

Showing country specific content on your Magento store

One of the beauties of Magento is the ability to create multiple stores from the same Magento backend. This enables you to create multiple language versions of your site with relative ease. However that may sometimes be overkill for what you need, and also may present quite a cost overhead as you’ve got to get your Products and CMS pages translated.

So what do you do if you only want to show a message to customers in a particular country? Well, we’ve just released our Sweetapple_Geolocation Extension as a free download – it might help you out.

Essentially it enables you to write a simple bit of code in your Magento templates to test the country a visitor to your site is coming from. You can then display a specific static block, or run any other code, just for people in that country or countries.

For example, this snippet will check if the person is in the UK, and only display the home_page_message_GB static block if the visitor to the store is browsing from a computer with a British IP Address.

$_ipHelper = $this->helper('sweetapple_geotargeting/data');
/* @var $_ipHelper Sweetapple_Geotargeting_Helper_Data */
$countryCodeFromIP = $_ipHelper->getCountryCodeFromIPAddress();
if( $countryCodeFromIP == "GB" ) {
//do something here, like load a specific static block...
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home_page_message_GB')->toHtml();
}

You can also use this technique to leave placeholders in your template for dynamically displayed static blocks. For example,

$_ipHelper = $this->helper('sweetapple_geotargeting/data');
/* @var $_ipHelper Sweetapple_Geotargeting_Helper_Data */
$countryCodeFromIP = $_ipHelper->getCountryCodeFromIPAddress();
//show a dynamically named static block.
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home_page_message_' . $countryCodeFromIP )->toHtml();
}

It’s not a perfect solution I’ll admit. Someone might be using a Web Proxy, a VPN, or on holiday in Spain but wanting to deliver or order in the UK. But it does add some flexibility to targeting overseas shoppers.

Looking for a freelance Magento developer? We’re based just outside Bath, but have clients in Bristol, Swindon and across the South West and we’d love to help you get your e-commerce website started. Don’t hesitate to give us a call on 01380 830224.

Whether it’s with custom theme development, custom Extension development, SEO, data import, Magento tuition or store migration, we can help you out. You’ll get professional, quick and sensible advice, but without having to pay horrendous agency rates. 

This entry was posted in Magento. Bookmark the permalink.

Comments

Sorry, comments are closed on this page.