1function initializeCartOptionsStyling(scope = document) { 2 // Check if we're on the cart page or initializing for modal 3 const isRelevantContext = document.body.classList.contains('woocommerce-cart') || 4 (scope instanceof HTMLElement && scope.id === 'cart-modal'); 5 6 if (!isRelevantContext) { 7 // Not the cart page or relevant modal, exit the script. 8 return; 9 } 10 11 // Find all cart item forms or containers 12 const cartItemContainers = scope.querySelectorAll('.cart-item'); 13 14 cartItemContainers.forEach((cartItem) => { 15 const listItems = cartItem.querySelectorAll('.bos4w-display-options li'); 16 const radioButtons = cartItem.querySelectorAll('.bos4w-buy-type'); 17 18 if (!radioButtons.length || !listItems.length) { 19 console.warn('Required elements not found, retrying...'); 20 setTimeout(() => initializeCartOptionsStyling(scope), 500); 21 return; 22 } 23 24 // Attempt to extract fixedPricesData from the cart itemâs data attribute 25 const dataAttr = cartItem.dataset.fixedPrices; 26 let fixedPricesData = []; 27 28 if (dataAttr) { 29 try { 30 fixedPricesData = JSON.parse(dataAttr); 31 } catch (e) { 32 console.warn('Invalid fixedPrices JSON in cartItem:', e, dataAttr); 33 } 34 } 35 36 if (Array.isArray(fixedPricesData) && fixedPricesData.length > 0) { 37 // Normalize visibility_option just in case 38 const normalized = fixedPricesData.map((item) => ({ 39 ...item, 40 visibility_option: item.visibility_option || 'both', 41 })); 42 43 FixedPriceUtils.applyFrequencyVisibility(cartItem, normalized); 44 } else { 45 console.warn('No fixedPricesData found or empty array on cartItem:', cartItem); 46 } 47 48 // Add event listener to each radio button to update the active-option class 49 radioButtons.forEach((radio) => { 50 radio.addEventListener('change', function () { 51 // Remove active class from all list items 52 listItems.forEach(li => li.classList.remove('active-option')); 53 54 // Add active class to the closest list item of the checked radio button 55 if (radio.checked) { 56 const listItem = radio.closest('li'); 57 if (listItem) { 58 listItem.classList.add('active-option'); 59 } 60 } 61 }); 62 63 // Initialize the active-option class based on the current selection 64 if (radio.checked) { 65 const listItem = radio.closest('li'); 66 if (listItem) { 67 listItem.classList.add('active-option'); 68 } 69 } 70 }); 71 }); 72} 73 74// Initialize for the cart page 75document.addEventListener('DOMContentLoaded', function () { 76 initializeCartOptionsStyling(); 77}); 78 79// Reinitialize after WooCommerce AJAX events 80jQuery(document.body).on('updated_cart_totals wc_fragments_refreshed', function () { 81 initializeCartOptionsStyling(); 82});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.