tag document.addEventListener('DOMContentLoaded', function() { // Function to auto-select Express shipping function selectExpressShipping() { // Check if we're on a page with shipping options const shippingOptionsContainer = document.querySelector('.radio-wrapper.content-box__row'); if (!shippingOptionsContainer) return; // Find all shipping options const shippingOptions = document.querySelectorAll('input[name="checkout[shipping_rate][id]"]'); if (shippingOptions.length === 0) return; // Look for Express shipping option by checking the label text let expressOption = null; for (const option of shippingOptions) { const label = option.parentElement.querySelector('label'); if (label && (label.textContent.toLowerCase().includes('express') || label.textContent.toLowerCase().includes('expedited') || label.textContent.toLowerCase().includes('fast'))) { expressOption = option; break; } } // If Express option found, select it if (expressOption) { expressOption.checked = true; expressOption.click(); // Trigger click to ensure any dependent scripts run console.log('Express shipping automatically selected'); } else { // If Express not found, select the fastest option (usually the most expensive) let highestPrice = 0; let fastestOption = null; for (const option of shippingOptions) { const priceText = option.parentElement.querySelector('.content-box__emphasis'); if (priceText) { const price = parseFloat(priceText.textContent.replace(/[^0-9.]/g, '')); if (price > highestPrice) { highestPrice = price; fastestOption = option; } } } if (fastestOption) { fastestOption.checked = true; fastestOption.click(); console.log('Fastest shipping option automatically selected'); } } } // Run immediately and also when Shopify refreshes sections selectExpressShipping(); // Observe DOM changes to catch when shipping options are loaded dynamically const observer = new MutationObserver(function(mutations) { for (const mutation of mutations) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0 && document.querySelector('input[name="checkout[shipping_rate][id]"]')) { selectExpressShipping(); } } }); // Start observing the document body for shipping option changes observer.observe(document.body, { childList: true, subtree: true }); });