1jQuery(document).ready(function($) 2{ 3 // Since selecting a shipping method, the shipping estimate will be updated via Ajax, 4 // this is the only way I found to hook into this. 5 var proxied = window.XMLHttpRequest.prototype.send; 6 window.XMLHttpRequest.prototype.send = function() { 7 var pointer = this; 8 var intervalId = window.setInterval(function(){ 9 if(pointer.readyState != 4){ 10 return; 11 } 12 //Here is where you can add any code to process the response. 13 //If you want to pass the Ajax request object, pass the 'pointer' below 14 clearInterval(intervalId); 15 replaceDates($); 16 remove_economy_shipping($,true); 17 18 }, 1);//I found a delay of 1 to be sufficient, modify it as you need. 19 return proxied.apply(this, [].slice.call(arguments)); 20 }; 21 22 // Shipping method events 23 replaceDates($); 24 remove_economy_shipping($,false); 25 26 // Update the pricing estimate on SIP when the purchase options method is changed 27 $('body').on('change', 'input[name="purchase-options"]:radio', function() { 28 updatePurchaseOptions($,$(this).val()); 29 }); 30 31 // Update the call to action above bag and pod size 32 var pa_size_indexes = document.querySelectorAll('ul.variable-items-wrapper[data-attribute_name="attribute_pa_size"] li').length; 33 $('body').find('ul.variable-items-wrapper[data-attribute_name="attribute_pa_size"]').each(function (i, el) { 34 $(el).on('click.wvs', 'li.variable-item:not(.selected):not(.radio-variable-item)', function (event) { 35 var current_index = $(this).index()+1; 36 update_size_cta($,current_index,pa_size_indexes); 37 }); 38 }); 39 40 var pod_qty_indexes = document.querySelectorAll('ul.variable-items-wrapper[data-attribute_name="attribute_quantity"] li').length; 41 $('body').find('ul.variable-items-wrapper[data-attribute_name="attribute_quantity"]').each(function (i, el) { 42 $(el).on('click.wvs', 'li.variable-item:not(.selected):not(.radio-variable-item)', function (event) { 43 var current_index = $(this).index()+1; 44 update_size_cta($,current_index,pod_qty_indexes); 45 }); 46 }); 47 48 // price per oz styling 49 price_per_oz_styling($); 50 51 // Create an account? Modal on checkout page 52 add_account_checkbox_modal($); 53 $('body').on('click', '#whatsthis-create-account', function(e) { 54 e.preventDefault(); 55 $("div.create-account-description").slideToggle(); 56 }); 57});// END DOCUMENT READY 58 59function replaceDates($) 60{ 61 $('ul#shipping_method li').each(function(i) 62 { 63 const origString = $(this).find('.porto-control-label').text(); 64 var dayRange = origString.replace(/(\$[0-9]\.[0-9][0-9])|(\$[0-9][0-9]\.[0-9][0-9])|[A-z]|\s|:|,/g, ""); 65 var dayArray = dayRange.split("-"); 66 67 var firstDate = new Date(Date.now()+dayArray[0]*24*60*60*1000); 68 var secondDate = new Date(Date.now()+dayArray[1]*24*60*60*1000); 69 70 let newEstimate = origString.replace(dayRange+" Business Days", " (" + formatDate(firstDate) + " - " + formatDate(secondDate) + ") - estimated"); 71 if (isNaN(dayArray[0]) || isNaN(dayArray[1])){ 72 return false; 73 }else{ 74 $(this).find('.porto-control-label').html(newEstimate); 75 } 76 77 }); 78} 79 80function remove_economy_shipping($,refresh) { 81 $('ul#shipping_method li').each(function(i) 82 { 83 var shippingMethod = $(this).find('input[type="radio"]').val(); 84 var shippingMethodType = shippingMethod.split(":"); 85 86 if (shippingMethodType[0] == 'free_shipping') 87 { 88 $(this).css( "color", "#0057fa" ); 89 $("ul#shipping_method li").eq(1).addClass('hidden'); 90 91 if($("ul#shipping_method li").eq(1).find('input[type="radio"]').is(":checked") 92 || $("ul#shipping_method li").eq(0).find('input[type="radio"]').is(":checked")) 93 { 94 $(this).find('input[type="radio"]').prop("checked", true).trigger("click"); 95 } 96 } 97 98 }); 99} 100 101function formatDate(date) 102{ 103 var d = new Date(date), 104 month = '' + (d.getMonth() + 1), 105 day = '' + d.getDate(), 106 year = d.getFullYear(); 107 return [month, day].join('/'); 108} 109 110function updatePurchaseOptions($, opt_val) 111{ 112 var product_variations = $('form.variations_form').data("product_variations"); 113 114 if ($('select#pa_size').find(':selected').val() != undefined) { 115 var sizeValue = $('select#pa_size').find(':selected').val(); 116 } 117 118 if ($('select[name=attribute_quantity]').find(':selected').val() != undefined) { 119 var sizeValue = $('select[name=attribute_quantity]').find(':selected').val(); 120 121 } 122 123 var item_sku = $('form.variations_form').data('product_id'); 124 125 for(var i = 0; i < product_variations.length; i++) { 126 127 if (product_variations[i].attributes.attribute_pa_size != undefined) 128 { 129 var variation_size = product_variations[i].attributes.attribute_pa_size; 130 } 131 132 if (product_variations[i].attributes.attribute_quantity != undefined) 133 { 134 var variation_size = product_variations[i].attributes.attribute_quantity; 135 } 136 137 if(variation_size === sizeValue) { 138 var price = product_variations[i].display_price; 139 var msrp = product_variations[i].display_regular_price; 140 } 141 } 142 143 144 var option_percent_off = $('select[name="subscription-options"]').find(':selected').data("percent_off"); 145 // clear all the checked attributes on the hidden radio inputs 146 147 $('input[name="convert_to_sub_'+item_sku+'"]').prop("checked", false); 148 if (opt_val == 'subscription') 149 { 150 var option_selected = $('select[name="subscription-options"]').find(':selected').val(); 151 var discounted_price = price - (price * (option_percent_off / 100)); 152 discounted_price = discounted_price.toFixed(2); 153 var updated_price = "<bdi><span class=\"woocommerce-Price-currencySymbol\">$</span>"+discounted_price+"</bdi>"; 154 $('ins > .woocommerce-Price-amount > bdi').replaceWith(updated_price); 155
156 // update subscription 157 $('input[name="convert_to_sub_'+item_sku+'"][value='+option_selected+']').prop("checked", true); 158 159 $('body').on('change', 'select[name="subscription-options"]', function() { 160 option_selected = $('select[name="subscription-options"]').find(':selected').val(); 161 $('input[name="convert_to_sub_'+item_sku+'"][value='+option_selected+']').prop("checked", true); 162 }); 163 164 } else { 165 var old_price = "<bdi><span class=\"woocommerce-Price-currencySymbol\">$</span>"+price+"</bdi>"; 166 $('ins > .woocommerce-Price-amount > bdi').replaceWith(old_price); 167 //clear other options first 168 $('input[name="convert_to_sub_'+item_sku+'"]').prop("checked", false); 169 $('li.one-time-option').find('input[name="convert_to_sub_'+item_sku+'"]').prop("checked", true); 170 171 172 } 173} 174 175function update_size_cta($,current_index,total_num_indexes) 176{ 177 var cta_off = "Upgrade to a larger size for instant savings."; 178 var cta_on = "You are getting the best possible deal!"; 179 if (current_index == total_num_indexes) 180 { 181 $('#size-cta').html(cta_on); 182 } 183 else 184 { 185 $('#size-cta').html(cta_off); 186 } 187} 188 189function price_per_oz_styling($) 190{ 191 $('#pa_size option').each(function(){ 192 if ($(this).val() != '') 193 { 194 var priceString = $(this).text().split(" "); 195 var newPriceString = '<span class="ppo-container">'+priceString[0]+'<span class="price-per-oz">'+priceString[1]+'</span></span>'; 196 $(".variable-item-span").each(function (index , value) 197 { 198 if ($(this).text() == priceString[0]+' '+priceString[1]){ 199 $(this).replaceWith(newPriceString); 200 } 201 }); 202 } 203 }); 204 205 $('#quantity option').each(function(){ 206 if ($(this).val() != '') 207 { 208 var priceString = $(this).text().split(" "); 209 var newPriceString = '<span class="ppo-container">'+priceString[0]+'<span class="price-per-oz">'+priceString[1]+'</span></span>'; 210 $(".variable-item-span").each(function (index , value) 211 { 212 if ($(this).text() == priceString[0]+' '+priceString[1]){ 213 $(this).replaceWith(newPriceString); 214 } 215 }); 216 } 217 }); 218} 219 220function add_account_checkbox_modal($){ 221 var where_to_stick_it = $('.woocommerce-account-fields > p.create-account'); 222 var new_html = '<a href="javascript:void(0);" id="whatsthis-create-account"><i class="fa fa-question-circle"></i></a>'; 223 new_html += '<div class="create-account-description" style="display: none;">'; 224 new_html += '<span class="create-account-description-text">'; 225 new_html += '<p>Create an account to save your shipping and billing information for future purchases.</p>'; 226 new_html += '</span>'; 227 new_html += '<div>'; 228 $(where_to_stick_it).append(new_html); 229}
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.