Abrir la aplicación móvil
Atención al cliente

¡Hola! ¿Necesita ayuda? No se preocupe, le atenderé con mucho gusto. Cuénteme qué ocurre y estaré encantado de ayudarle 💁

* ============================================================ Veterinaria Managua – País automático: Nicaragua (v2) ------------------------------------------------------------ Qué hace: 1. Si el carrito aún no tiene país, fija Nicaragua por la API de Ecwid (solo en ese caso, para no pisar datos guardados). 2. En el formulario del pedido busca el selector «País», lo pone en Nicaragua y avisa a Ecwid del cambio. 3. Oculta el campo SOLO cuando confirma que Nicaragua quedó seleccionada (y, si Ecwid lo expone, que el carrito lo registró). Si no lo confirma, el campo queda visible. 4. Nunca oculta una caja que contenga otro control además del país, y tiene límites de reintentos para no pelearse con la tienda. Dónde pegarlo: Sitio web → Editar sitio → Código JavaScript personalizado → Añadir código. Pegar tal cual, SIN etiquetas .) ============================================================ */ (function () { 'use strict'; if (window.__vmPaisNicaragua) return; /* evita doble ejecución */ window.__vmPaisNicaragua = true; var PAIS_NOMBRE = 'nicaragua'; var PAIS_CODIGO = 'NI'; var MARCA = 'vm-pais-ni-oculto'; var MAX_CAMBIOS = 3; /* veces que forzamos el valor en un mismo selector */ var MAX_INTENTOS = 8; /* lecturas del carrito para confirmar */ var estados = new WeakMap(); var pendiente = false; var apiIntentada = false; var css = document.createElement('style'); css.textContent = '.' + MARCA + '{display:none!important}'; (document.head || document.documentElement).appendChild(css); /* ---------- utilidades ---------- */ function esNicaraguaDireccion(d) { return !!d && (String(d.countryCode || '').toUpperCase() === PAIS_CODIGO || String(d.countryName || '').trim().toLowerCase() === PAIS_NOMBRE); } function esOpcionNicaragua(o) { return !!o && (o.textContent.trim().toLowerCase() === PAIS_NOMBRE || String(o.value || '').trim().toUpperCase() === PAIS_CODIGO); } function textoEtiqueta(s) { var fila = s.closest('.ec-form__row, .ec-form__cell, .form-control'); var t = fila && fila.querySelector('.ec-form__title, label'); var porId = s.id && document.querySelector('label[for="' + s.id + '"]'); return ((t ? t.textContent : '') + ' ' + (porId ? porId.textContent : '')).trim(); } function esSelectorDePais(s) { if (s.options.length < 50) return false; /* un país real tiene ~200 opciones */ var pistas = [s.name, s.id, s.getAttribute('autocomplete'), textoEtiqueta(s)] .join(' ').toLowerCase(); return /country|pa[ií]s/.test(pistas); } function cajaDelCampo(s) { var fila = s.closest('.ec-form__row'); var celda = s.closest('.ec-form__cell') || s.closest('.form-control__wrap') || s.closest('.form-control') || s.parentElement; if (fila && fila.querySelectorAll('input, select, textarea, button').length === 1) return fila; return celda; } function programar() { if (pendiente) return; pendiente = true; setTimeout(revisar, 300); } /* ---------- 1. prefijar por API solo si el carrito no tiene país ---------- */ function prefijarPorApi() { if (apiIntentada || !window.Ecwid || !Ecwid.Cart || !Ecwid.Cart.get) return; apiIntentada = true; try { Ecwid.Cart.get(function (c) { var dir = { countryName: 'Nicaragua', countryCode: PAIS_CODIGO }; var envio = c && c.shippingPerson, pago = c && c.billingPerson; try { if (!esNicaraguaDireccion(envio) && !(envio && (envio.countryCode || envio.countryName)) && typeof Ecwid.Cart.setAddress === 'function') { Ecwid.Cart.setAddress(dir, function () { programar(); }); } if (!esNicaraguaDireccion(pago) && !(pago && (pago.countryCode || pago.countryName)) && typeof Ecwid.Cart.setBillingAddress === 'function') { Ecwid.Cart.setBillingAddress(dir, function () { programar(); }); } } catch (e) { /* la API no es imprescindible */ } }); } catch (e) { /* idem */ } } /* ---------- 2 y 3. formulario ---------- */ function revisar() { pendiente = false; document.querySelectorAll('select').forEach(function (s) { try { revisarSelector(s); } catch (e) { /* seguir con el resto */ } }); } function revisarSelector(s) { if (!esSelectorDePais(s)) return; var opcion = Array.prototype.find.call(s.options, esOpcionNicaragua); if (!opcion) return; var caja = cajaDelCampo(s); if (!caja) return; var controles = caja.querySelectorAll('input, select, textarea, button'); var sePuedeOcultar = controles.length === 1 && controles[0] === s; var e = estados.get(s); if (!e) { e = { cambios: 0, intentos: 0, leyendo: false, confirmado: false }; estados.set(s, e); } /* forzar Nicaragua (con límite para no pelear con la tienda) */ if (s.value !== opcion.value) { caja.classList.remove(MARCA); e.confirmado = false; if (e.cambios >= MAX_CAMBIOS) return; e.cambios++; e.intentos = 0; s.value = opcion.value; s.dispatchEvent(new Event('input', { bubbles: true })); s.dispatchEvent(new Event('change', { bubbles: true })); programar(); return; } if (e.confirmado) { if (sePuedeOcultar) caja.classList.add(MARCA); return; } if (e.leyendo || e.intentos >= MAX_INTENTOS) return; e.intentos++; if (!window.Ecwid || !Ecwid.Cart || !Ecwid.Cart.get) { programar(); return; } e.leyendo = true; try { Ecwid.Cart.get(function (c) { e.leyendo = false; if (!s.isConnected || s.value !== opcion.value) return; var enPago = !!s.closest('.ec-cart-step--payment'); var dir = c && (enPago ? c.billingPerson : c.shi