1jQuery(function ($) { 2 "use strict"; 3 $('form.checkout').on('change.wt_sc_payment_method_change', 'input[name="payment_method"]', function () { 4 5 let t = {updateTimer: !1, dirtyInput: !1, 6 reset_update_checkout_timer: function () { 7 clearTimeout(t.updateTimer) 8 }, trigger_update_checkout: function () { 9 t.reset_update_checkout_timer(), t.dirtyInput = !1, 10 $(document.body).trigger("update_checkout") 11 } 12 }; 13 t.trigger_update_checkout(); 14 15 }); 16 17 18 $('document').ready(function(){ 19 20 /* After the coupon box click event was done */ 21 $(document).on("wt_sc_api_coupon_click_done", function(e){ 22 wt_unblock_node($( 'div.wt_coupon_wrapper')); 23 wt_unblock_node($("div.wt-mycoupons")); 24 wt_unblock_node($("div.wt_store_credit")); 25 }); 26 27 /** Handle keyboard Enter press on coupons */ 28 $( document ).on("keypress", '.wt-single-coupon.active-coupon', function(e){ 29 if( 13 === e.which ) { // Enter key 30 $( this ).trigger( 'click' ); 31 } 32 } ); 33 34 $(document).on("click", '.wt-single-coupon.active-coupon', function(){ 35 36 if(!$('.woocommerce-notices-wrapper').length){ 37 $('#main').prepend('<div class="woocommerce-notices-wrapper"></div>'); 38 } 39 40 const coupon_code = ( typeof $(this).attr('data-code') === 'undefined' ? $(this).find('code').text() : $(this).attr('data-code') ); 41 const coupon_id = $(this).attr('data-id'); 42 43 $('div.wt_coupon_wrapper, div.wt_store_credit').each(function(){ 44 if($(this).find('.wt-single-coupon').length) 45 { 46 wt_block_node($(this)); 47 } 48 }); 49 50 /* For checkout block compatibility */ 51 if( $('.wc-block-checkout, .wc-block-cart').length ) { 52 53 const coupon_click_event = new CustomEvent("wt_sc_api_coupon_clicked", { 54 detail:{ 'coupon_code' : coupon_code, 'coupon_id': coupon_id} 55 }); 56 document.dispatchEvent(coupon_click_event); 57 return false; 58 } 59 60 const data = { 61 'coupon_code' : coupon_code, 62 'coupon_id' : coupon_id, 63 '_wpnonce' : WTSmartCouponOBJ.nonces.apply_coupon 64 }; 65 66 $.ajax({ 67 type: "POST", 68 async: true, 69 url: WTSmartCouponOBJ.wc_ajax_url + 'apply_coupon_on_click', 70 data: data, 71 success: function (response) { 72 if ( $( '.woocommerce-cart-form' ).length) { 73 update_cart(true); // need only for cart page 74 } 75 76 wt_unblock_node( $( 'div.wt_coupon_wrapper' ) ); 77 wt_unblock_node($("div.wt-mycoupons")); 78 wt_unblock_node($("div.wt_store_credit")); 79 80 $( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); 81 show_notice( response ); 82 $(document.body).trigger("update_checkout"); 83 $( document.body ).trigger("applied_coupon"); 84 85 $('html, body').animate({ 86 scrollTop: $(".woocommerce").offset().top 87 }, 1000); 88 } 89 }); 90 91 }); 92 93 /* For checkout block */ 94 if( $('.wc-block-checkout').length ) { 95 $( document ).on("click", '[name="radio-control-wc-payment-method-options"]', function(){ 96 WTSmartCouponOBJ.payment_method = $('[name="radio-control-wc-payment-method-options"]:checked').val(); 97 let parent_div = $('[name="radio-control-wc-payment-method-options"]').parents('.wc-block-components-radio-control'); 98 parent_div.find('.wc-block-components-radio-control__option').removeClass('wc-block-components-radio-control__option-checked'); 99 wbte_set_block_checkout_values(); 100 }); 101 102 setTimeout( wbte_set_block_checkout_values, 200); 103 } 104 105 }); 106 107 /** Update payment method on session, if coupons are changed update checkout */ 108 $( document.body ).on( 'payment_method_selected', 109 function() { 110 jQuery( document ).on( "updated_checkout", 111 function(){ 112 const selectedPaymentMethod = $( 'form.checkout' ).find( 'input[name="payment_method"]:checked' ).val(); 113 $.ajax({ 114 type: "POST", 115 url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_update_payment_method_on_session', 116 data: { 117 'payment_method': selectedPaymentMethod, 118 '_wpnonce': WTSmartCouponOBJ.nonces.public 119 }, 120 success: function( response ) { 121 if ( response ) { 122 $( 'form.checkout' ).trigger( 'update' ); 123 } 124 } 125 }); 126 } 127 ); 128 } 129 ); 130 131 const wbte_set_block_checkout_values = function() { 132 133 let payment_method = ''; 134 const shipping_method = {}; 135 136 if( $('[name="radio-control-wc-payment-method-options"]').length ) { 137 138 /* Prepare payment method from radio button */ 139 payment_method = $('[name="radio-control-wc-payment-method-options"]:checked').val(); 140 141 } 142 143 /* Prepare shipping method from radio button */ 144 if( $('.wc-block-components-shipping-rates-control input[type="radio"]').length ) { 145 $('.wc-block-components-shipping-rates-control input[type="radio"]:checked').each(function(index){ 146 shipping_method[index] = $(this).val(); 147 }); 148 } 149 150 /* Store the value to global variable to prevent future auto refresh blocking */ 151 WTSmartCouponOBJ.shipping_method = shipping_method; 152 WTSmartCouponOBJ.payment_method = payment_method; 153 154 155 /* Send ajax request to set the value */ 156 let order_summary_block = $('.wp-block-woocommerce-checkout-order-summary-block'); 157 wt_block_node( order_summary_block ); 158 159 $.ajax({ 160 type: "POST", 161 async: true, 162 url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_set_block_checkout_values', 163 data: { '_wpnonce': WTSmartCouponOBJ.nonces.public, 'payment_method': payment_method, 'shipping_method': shipping_method }, 164 dataType: 'json', 165 success:function( data ) { 166 wt_unblock_node( order_summary_block ); 167 }, 168 error:function() { 169 wt_unblock_node( order_summary_block ); 170 } 171 }); 172 173 /* Trigger checkout block refresh */ 174 setTimeout(function(){ 175 const checkout_value_updated_event = new CustomEvent("wbte_sc_checkout_value_updated", { 176 detail:{ 'payment_method' : payment_method, 'shipping_method': shipping_method } 177 }); 178 document.dispatchEvent(checkout_value_updated_event); 179 }, 1000); 180 181 } 182 183 184 /** 185 * Function from cart.js by woocommmerce 186 * @param {bool} preserve_notices 187 */ 188 const update_cart = function( preserve_notices ) { 189 const $form = $( '.woocommerce-cart-form' ); 190 wt_block_node( $form ); 191 wt_block_node( $( 'div.cart_totals' ) ); 192 193 194 195 // Make call to actual form post URL. 196 $.ajax( { 197 type: $form.attr( 'method' ), 198 url: $form.attr( 'action' ), 199 data: $form.serialize(), 200 dataType: 'html', 201 success: function( response ) { 202 update_wc_div( response, preserve_notices ); 203 }, 204 complete: function() { 205 wt_unblock_node( $form ); 206 wt_unblock_node( $( 'div.cart_totals' ) ); 207 } 208 } ); 209 } 210 211 212 /** 213 * 214 * @param {string} html_str 215 * @param {bool} preserve_notices 216 */ 217 const update_wc_div = function( html_str, preserve_notices ) { 218 const $html = $.parseHTML( html_str ); 219 const $new_form = $( '.woocommerce-cart-form', $html ); 220 const $new_totals = $( '.cart_totals', $html ); 221 const $notices = $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html ); 222 223 // No form, cannot do this. 224 if ( $( '.woocommerce-cart-form' ).length === 0 ) { 225 window.location.href = window.location.href; 226 return; 227 } 228 229 // Remove errors 230 if ( ! preserve_notices ) { 231 $( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); 232 } 233 234 if ( $new_form.length === 0 ) {
235 // If the checkout is also displayed on this page, trigger reload instead. 236 if ( $( '.woocommerce-checkout' ).length ) { 237 window.location.href = window.location.href; 238 return; 239 } 240 241 // No items to display now! Replace all cart content. 242 const $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' ); 243 $( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html ); 244 245 // Display errors 246 if ( $notices.length > 0 ) { 247 show_notice( $notices ); 248 } 249 } else { 250 // If the checkout is also displayed on this page, trigger update event. 251 if ( $( '.woocommerce-checkout' ).length ) { 252 $( document.body ).trigger( 'update_checkout' ); 253 } 254 255 $( '.woocommerce-cart-form' ).replaceWith( $new_form ); 256 $( '.woocommerce-cart-form' ).find( ':input[name="update_cart"]' ).prop( 'disabled', true ); 257 258 if ( $notices.length > 0 ) { 259 show_notice( $notices ); 260 } 261 262 update_cart_totals_div( $new_totals ); 263 } 264 265 $( document.body ).trigger( 'updated_wc_div' ); 266 }; 267 268 269 /** 270 * Function from woocmmerce cart.js 271 * @param {string} html_str 272 */ 273 const update_cart_totals_div = function( html_str ) { 274 $( '.cart_totals' ).replaceWith( html_str ); 275 $( document.body ).trigger( 'updated_cart_totals' ); 276 }; 277 278 279 280 /** 281 * function from cart.js by wooocommerce 282 * @param { jQuery object } node 283 */ 284 const wt_block_node = function( node ) { 285 286 node.addClass( 'processing' ); 287 288 if(typeof $.fn.block === 'function') 289 { 290 node.block({ 291 message: null, 292 overlayCSS: { 293 background: '#fff', 294 opacity: 0.6 295 } 296 }); 297 } 298 } 299 window.wbte_sc_block_node = wt_block_node; 300 301 /** 302 * function from cart.js by wooocommerce 303 * @param {jQuery object} $node 304 */ 305 const wt_unblock_node = function( node ) { 306 307 node.removeClass( 'processing' ); 308 309 if(typeof $.fn.unblock === 'function') 310 { 311 node.unblock(); 312 } 313 }; 314 window.wbte_sc_unblock_node = wt_unblock_node; 315 316 317 const show_notice = function( html_element, $target ) { 318 if ( ! $target ) { 319 $target = $( '.woocommerce-notices-wrapper:first' ) || $( '.cart-empty' ).closest( '.woocommerce' ) || $( '.woocommerce-cart-form' ); 320 } 321 $target.prepend( html_element ); 322 }; 323 324});
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.