Created
April 27, 2015 15:42
-
-
Save donohfx/29ecf2b629770d80950e to your computer and use it in GitHub Desktop.
Multilanguage and Multicurrency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is an example of automatic currency switching based on IP as well as language selection using Langify and redirects. | |
All domains should be set up in Langify with their appropriate languages. I'd recommend placing this code in its own snippet | |
and including it near the </body> tag in your theme.liquid | |
Dependencies: | |
- currencies.js (https://github.com/carolineschnapp/currencies) | |
- Langify (https://apps.shopify.com/langify) | |
- A Shopify Store (well, should work anywhere, but only tested on Shopify) | |
--> | |
<script> | |
jQuery.ajax( { | |
url: '//freegeoip.net/json/', | |
type: 'GET', | |
dataType: 'jsonp', | |
success: function(location) { | |
if (location.country_code == 'CA') { // Default shop currency | |
$("#currencies").val("CAD"); | |
$("#currencies").change(); | |
// Redirect them to the Canadian store. | |
window.top.location.href = 'http://canada.domain.com'; | |
alert("you are from Canada"); // remove alert lines when done testing | |
} else if (location.country_code == 'AU') { // Secondary currency | |
$("#currencies").val("AUD"); | |
$("#currencies").change(); | |
window.top.location.href = 'http://au.domain.com'; | |
alert("you are from AU"); | |
} else if (location.country_code == 'US') { // Secondary currency | |
$("#currencies").val("USD"); | |
$("#currencies").change(); | |
window.top.location.href = 'http://domain.com'; | |
alert("you are from US"); | |
} else { // Fallback currency | |
$("#currencies").val("EUR"); | |
$("#currencies").change(); | |
window.top.location.href = 'http://global.domain.com'; | |
alert("you are from elsewhere"); | |
} | |
// Let the scripts in 'currencies.liquid' handle the rest | |
$('[name=currencies]').change(); | |
} | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment