A lot of businesses create multiple online stores with Shopify that are country specific. Each Shopify store will serve a specific visitor country. So the question is: “How can I automatically redirect visitors to correct country based Shopify store, based on their country or IP Address?”
For example, we have 4 sites:
- www.domain.us – Customers from United States
- www.domain.ca – Customers from Canada
- www.domain.au – Customers from Australia
- www.domain.com – Customers from rest the world
Don’t panic. I will guide you through this simple process.
To achieve this functionality, we will need help of a service called GeoPlugin.Net (GeoPlugin) to detected visitor’s location. GeoPlugin provides a public HTTP API for software developers to search the geolocation of IP addresses. This is the code.
Implementation:
Here is the code that needs to be added inside yourtag:
This will return with: IP, country code, country name, region code, region name, city, latitude, longitude, currency code…
To get your country code, please find your country specific code here.
Now we will have to write some code for this to work:
For United States store:
For Canada store:
For rest of the world:
That’s it! Feel free to drop a message if you have any questions.