Created
December 24, 2019 13:39
-
-
Save octipus/ac95da62d3538eb91b95126d7da1d50a to your computer and use it in GitHub Desktop.
Shopify Script for detecting users location and apply local currency
This file contains hidden or 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
//to be placed in theme.js or custom.js | |
//script for redirecting users to use local currency | |
$.get("https://ipinfo.io/json", function (response) { | |
//console.log (response.country) | |
var check = false; | |
if (response.country === 'GB') { | |
//console.log("hello UK"); | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=gbp'; | |
localStorage["check"] = true; | |
} | |
}else if (response.country === 'US') { | |
//console.log("hello US"); | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=usd'; | |
localStorage["check"] = true; | |
} | |
}else if (response.country === 'AU') { | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=aud'; | |
localStorage["check"] = true; | |
} | |
}else if (response.country === 'CA') { | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=cad'; | |
localStorage["check"] = true; | |
} | |
}else if (response.country === 'JP') { | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=jpy'; | |
localStorage["check"] = true; | |
} | |
}else if (response.country === 'AL' || response.country === 'AT'|| response.country === 'BE'|| response.country === 'CY'|| response.country === 'EE'|| response.country === 'FI'|| response.country === 'FR'|| response.country === 'DE'|| response.country === 'GR'|| response.country === 'IE'|| response.country === 'IT'|| response.country === 'LV'|| response.country === 'LT'|| response.country === 'LU'|| response.country === 'MT'|| response.country === 'NL'|| response.country === 'PT'|| response.country === 'SK'|| response.country === 'SI'|| response.country === 'ES'|| response.country === 'EZ') { | |
if(!localStorage["check"]) { | |
window.location.search += '?currency=eur'; | |
localStorage["check"] = true; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment