Detect país por IP como fallback de timezone en precios
This commit is contained in:
@@ -12,14 +12,33 @@
|
||||
</script>
|
||||
<script>
|
||||
(function () {
|
||||
var currency = 'usd';
|
||||
try {
|
||||
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (tz && tz.indexOf('America/Argentina') === 0) {
|
||||
currency = 'ars';
|
||||
}
|
||||
} catch (e) {}
|
||||
document.documentElement.setAttribute('data-currency', currency);
|
||||
function applyCurrency(currency) {
|
||||
document.documentElement.setAttribute('data-currency', currency);
|
||||
}
|
||||
|
||||
function countryFromTimeZone() {
|
||||
try {
|
||||
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (tz && tz.indexOf('America/Argentina') === 0) return 'AR';
|
||||
} catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
var country = countryFromTimeZone();
|
||||
applyCurrency(country === 'AR' ? 'ars' : 'usd');
|
||||
|
||||
var controller = new AbortController();
|
||||
var timer = setTimeout(function () { controller.abort(); }, 3000);
|
||||
|
||||
fetch('https://get.geojs.io/v1/ip/country.json', { signal: controller.signal })
|
||||
.then(function (res) { return res.json(); })
|
||||
.then(function (data) {
|
||||
if (data && typeof data.country === 'string' && data.country) {
|
||||
applyCurrency(data.country === 'AR' ? 'ars' : 'usd');
|
||||
}
|
||||
})
|
||||
.catch(function () {})
|
||||
.finally(function () { clearTimeout(timer); });
|
||||
})();
|
||||
</script>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
|
||||
Reference in New Issue
Block a user