var ciudadesTDF = {
'Ushuaia': 'Ushuaia',
'Río Grande': 'Río Grande',
'Tolhuin': 'Tolhuin'
};function reemplazarCampoCiudad(tipo) {
var provSelector = document.querySelector('#' + tipo + '_state');
var ciudadInput = document.querySelector('#' + tipo + '_city');if (!provSelector || !ciudadInput) return;if (ciudadInput.tagName.toLowerCase() === 'select') return;if (provSelector.value !== 'V') return;var nuevoSelect = document.createElement('select');
nuevoSelect.name = ciudadInput.name;
nuevoSelect.id = ciudadInput.id;
nuevoSelect.className = ciudadInput.className;var optionVacia = document.createElement('option');
optionVacia.value = '';
optionVacia.textContent = 'Seleccioná una ciudad';
nuevoSelect.appendChild(optionVacia);for (var ciudad in ciudadesTDF) {
var opt = document.createElement('option');
opt.value = ciudad;
opt.textContent = ciudad;
if (ciudad === ciudadInput.value) opt.selected = true;
nuevoSelect.appendChild(opt);
}ciudadInput.parentNode.replaceChild(nuevoSelect, ciudadInput);
}function iniciarReemplazo(tipo) {
var ciudadWrapper = document.querySelector('#' + tipo + '_city');
if (!ciudadWrapper || !ciudadWrapper.parentNode || !ciudadWrapper.parentNode.parentNode) return;var target = ciudadWrapper.parentNode.parentNode;var observer = new MutationObserver(function () {
reemplazarCampoCiudad(tipo);
});observer.observe(target, { childList: true, subtree: true });reemplazarCampoCiudad(tipo);
}document.addEventListener('DOMContentLoaded', function () {
iniciarReemplazo('billing');
iniciarReemplazo('shipping');
});