1window.onload = function() { 2 3/* ========================================== WOO ADD-ONS COMPATIBILITY START ================================================= */ 4 5 jQuery(document).ready(function($) { 6 7 function wc_pyp_price_format(price, plain) { 8 var remove = wc_pyp_vars.currency_format_decimal_sep, 9 position = wc_pyp_vars.currency_position, 10 symbol = wc_pyp_vars.currency_symbol, 11 trim_zeros = wc_pyp_vars.currency_format_trim_zeros, 12 decimals = parseInt(wc_pyp_vars.wc_price_decimal); 13 14 plain = typeof(plain) === 'undefined' ? false : false; 15 16 var formatted_price = String(price); 17 18 if (trim_zeros == 'yes' && decimals > 0) { 19 for (var i = 0; i < decimals; i++) { 20 remove = remove + '0'; 21 } 22 formatted_price = formatted_price.replace(remove, ''); 23 } else { 24 var formatted_price = parseFloat(price).toFixed(decimals); 25 } 26 27 // Add currency symbol 28 var formatted_symbol = plain ? symbol : '<span class="woocommerce-Price-currencySymbol">' + symbol + '</span>'; 29 if ('left' === position) { 30 formatted_price = formatted_symbol + formatted_price; 31 } else if ('right' === position) { 32 formatted_price = formatted_price + formatted_symbol; 33 } else if ('left_space' === position) { 34 formatted_price = formatted_symbol + ' ' + formatted_price; 35 } else if ('right_space' === position) { 36 formatted_price = formatted_price + ' ' + formatted_symbol; 37 } 38 39 // Wrap in span if not plain 40 formatted_price = plain ? formatted_price : '<span class="woocommerce-Price-amount amount">' + formatted_price + '</span>'; 41 42 return formatted_price; 43 } 44 45 function updateAddonPrice() { 46 47 var customPrice = parseFloat(jQuery('input#custom_price').val()); 48 var ProductAddonPrice = isNaN(customPrice) ? 0 : customPrice; 49 50 // Set the raw price and price data attributes 51 jQuery('#product-addons-total').data('raw-price', ProductAddonPrice).attr('data-raw-price', ProductAddonPrice).data('price', ProductAddonPrice).attr('data-price', ProductAddonPrice); 52 53 // Update the price on the UI 54 jQuery('.product-addon-totals ul li:first-child .wc-pao-col2 strong').html(wc_pyp_price_format(ProductAddonPrice)); 55 jQuery('.wc-pao-subtotal-line .amount').html(wc_pyp_price_format(ProductAddonPrice)); 56 57 var totalAddonPrice = 0; // Start with the custom price 58 59 // Loop through each addon to calculate the total price dynamically 60 jQuery('.product-addon-totals ul li').each(function() { 61 if (!jQuery(this).hasClass('wc-pao-subtotal-line')) { 62 63 64 65 // Handle different price types (percentage or fixed) 66 var selectedOption = jQuery('.wc-pao-addon-field').find('option:selected'); 67 var priceType = selectedOption.data('price-type'); 68 var selectedPrice = parseFloat(selectedOption.data('price')) || 0; 69 70 if (priceType === 'percentage_based') { 71 // Apply percentage-based price calculation to the ProductAddonPrice only once 72 var percentagePrice = (ProductAddonPrice * selectedPrice) / 100; 73 if ( percentagePrice > 0 ) { 74 jQuery('.product-addon-totals ul li:nth-child(2) .wc-pao-col2 .amount').html(wc_pyp_price_format(percentagePrice)); 75 }else { 76 jQuery('.product-addon-totals ul li:nth-child(2) .wc-pao-col2 .amount').html('-'); 77 78 } 79 totalAddonPrice = ProductAddonPrice + percentagePrice; // Calculate the total price based on the percentage 80 } else { 81 // For fixed prices or other types, accumulate the amount normally 82 var amountText = jQuery(this).find('.wc-pao-col2 .amount').text().trim(); 83 amountText = amountText.replace(/[^\d.-]/g, ''); 84 var amount = parseFloat(amountText); 85 if (amount > 0) { 86 totalAddonPrice += amount; 87 } 88 } 89 } 90 }); 91 92 // Update the subtotal line and hidden field with the total addon price 93 jQuery('.wc-pao-subtotal-line .amount').html(wc_pyp_price_format(totalAddonPrice));
94 jQuery('#data-price').val(totalAddonPrice); 95} 96 97 98 99 100 101 updateAddonPrice(); 102 103 jQuery(document).on('change', '.wc-pao-addon-field', function(event) { 104 updateAddonPrice(); 105 }); 106 107 jQuery(document).on('input change', 'input#custom_price', function(event) { 108 event.stopPropagation(); 109 110 setTimeout(function(){ 111 var container = jQuery('.wc-pao-addons-container'); 112 container.find('input').each(function () { 113 jQuery(this).trigger('change'); 114 }); 115 },500); 116 117 updateAddonPrice(); 118 }); 119 120 jQuery('.bundled_product_checkbox').on('change', function(event) { 121 event.stopPropagation(); 122 123 }); 124 125 126/* ========================================== WOO ADD-ONS COMPATIBILITY END ================================================= */ 127 128 129 130 131/* ========================================== PRODUCT BUNDLE COMPATIBILITY START ================================================= */ 132 133 134 // pyp_add_bundle_custom_price_field(); 135 136 setTimeout(function(){ 137 pyp_add_bundle_custom_price_field(); 138 },1000); 139 140 $(".variations_form").on( 141 "woocommerce_variation_select_change", 142 function () { 143 setTimeout(function(){ 144 pyp_add_bundle_custom_price_field(); 145 },1000); 146 } 147 ); 148 149 function pyp_add_bundle_custom_price_field(value){ 150 151 if($('.product-type-bundle').length > 0 && $('.product-type-bundle .wc-pyp-price-options').length > 0){ 152 153 let subtotal = 0; 154 var pyp_custom_price = 0; 155 156 pyp_custom_price = (typeof value === 'undefined') 157 ? parseFloat($('.wc-pyp-price-options #custom_price').val()) || 0 158 : parseFloat(value) || 0; 159 160 if (!pyp_custom_price || pyp_custom_price < 0) { 161 // Disable the button if input is empty or less than 0 162 $('.single_add_to_cart_button').prop('disabled', true); 163 } else { 164 // Enable the button otherwise 165 $('.single_add_to_cart_button').prop('disabled', false); 166 } 167 168 $('.bundled_product').each(function () { 169 var bundle_item = $(this); 170 171 var cart_bundle_element = bundle_item.find('.cart'); 172 var prod_id = cart_bundle_element.data('product_id'); 173 174 var customPriceInput = bundle_item.find('#custom_price'); 175 if (customPriceInput.length) { 176 customPriceInput.attr('name', 'custom_price_' + prod_id); 177 } 178 179 var pyp_cp_inp = bundle_item.find('.wc-pyp-price-options input'); 180 pyp_cp_inp.each(function () { 181 var price = parseFloat($(this).val()) || 0; 182 subtotal += price; 183 }); 184 185 var get_bundle_rp = bundle_item.find('.bundled_item_cart_details .woocommerce-Price-amount'); 186 if (get_bundle_rp.length > 0 && bundle_item.find('.wc-pyp-price-options').length <= 0) { 187 188 var itemPrice = parseFloat(get_bundle_rp.text().trim().replace(/[^\d.-]/g, '')) || 0; 189 subtotal += itemPrice; 190 } 191 192 var bundle_price_element = $('.bundle_price .woocommerce-Price-amount'); 193 if (bundle_price_element.length > 0) { 194 bundle_price_element.html(wc_pyp_price_format((subtotal + pyp_custom_price).toFixed(wc_pyp_vars.wc_price_decimal))); 195 } 196 }); 197 } 198 } 199 200 201 202 $(document).on('input', '.wc-pyp-price-options input', function () { 203 204 var value = $('input[name="custom_price"]').val(); 205 if(typeof value === 'undefined'){ 206 value = 0; 207 } 208 pyp_add_bundle_custom_price_field(value); 209 210 }); 211 212 213 // Initial run on page load 214 $(document).ready(pyp_add_bundle_custom_price_field(value = 0)); 215 }); 216 217 218 219/* ========================================== PRODUCT BUNDLE COMPATIBILITY END ================================================= */ 220 221 jQuery(document).ready(function ($) { 222 function toggleAddToCartButton() { 223 const customPriceValue = $('#custom_price').val(); 224 const customPrice = parseFloat(customPriceValue); 225 226 if($('.wc-pyp-price-options').length == 1){ 227 if (!customPriceValue || customPrice < 0) { 228 // Disable the button if input is empty or less than 0 229 $('.single_add_to_cart_button').prop('disabled', true); 230 } else { 231 // Enable the button otherwise 232 $('.single_add_to_cart_button').prop('disabled', false); 233 } 234 } 235 } 236 237 // Run the function on page load 238 toggleAddToCartButton(); 239 240 // Attach the function to the input and change events 241 $('#custom_price').on('input change', toggleAddToCartButton); 242 }); 243 244 245}; 246 247
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.