Quality
Guarantee
Fast
Shipping
Secure
Payments
Quality
Guarantee
Fast
Shipping
Secure
Payments
in layout/theme.liquid */ (function(){ function updateURLForVariant(variantId){ if(!variantId) return; try{ var url = new URL(window.location.href); url.searchParams.set('variant', variantId); // replace state so back/forward isn't cluttered window.history.replaceState({}, '', url.toString()); }catch(e){ /* ignore URL errors */ } } function initVariantWatcher(){ // If there's a select element for variant (common) var select = document.querySelector('select[name="id"]'); if(select){ // update now with current selection updateURLForVariant(select.value); select.addEventListener('change', function(e){ updateURLForVariant(e.target.value); }); return; } // Otherwise look for radio buttons for variants var radios = document.querySelectorAll('input[name="id"][type="radio"]'); if(radios && radios.length){ radios.forEach(function(r){ if(r.checked) updateURLForVariant(r.value); r.addEventListener('change', function(e){ if(e.target.checked) updateURLForVariant(e.target.value); }); }); return; } // Fallback: listen for common Shopify custom events if theme triggers them document.addEventListener('variant:changed', function(e){ try{ if(e.detail && e.detail.variant && e.detail.variant.id) updateURLForVariant(e.detail.variant.id); else if(e.variant && e.variant.id) updateURLForVariant(e.variant.id); }catch(err){} }); // If variant UI loads later (AJAX), try again after small delays var tries = 0; var poll = setInterval(function(){ tries++; if(document.querySelector('select[name="id"]') || document.querySelectorAll('input[name="id"][type="radio"]').length){ clearInterval(poll); initVariantWatcher(); } else if(tries>20){ clearInterval(poll); } }, 300); } // Run on DOM ready if(document.readyState === 'complete' || document.readyState === 'interactive'){ setTimeout(initVariantWatcher, 50); } else { document.addEventListener('DOMContentLoaded', initVariantWatcher); } })();