Detect país por IP como fallback de timezone en precios

This commit is contained in:
Jose Selesan
2026-09-15 20:17:35 -03:00
parent f85eb377ae
commit 3cab57a435

View File

@@ -12,14 +12,33 @@
</script> </script>
<script> <script>
(function () { (function () {
var currency = 'usd'; function applyCurrency(currency) {
try { document.documentElement.setAttribute('data-currency', currency);
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone; }
if (tz && tz.indexOf('America/Argentina') === 0) {
currency = 'ars'; function countryFromTimeZone() {
} try {
} catch (e) {} var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
document.documentElement.setAttribute('data-currency', currency); 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>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>