1jQuery(function ($) { 2 "use strict"; 3 $('form.checkout').on('change.wt_sc_payment_method_change', 'input[name="payment_method"]', function () { 4 5 var 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 var coupon_code = ( typeof $(this).attr('data-code') === 'undefined' ? $(this).find('code').text() : $(this).attr('data-code') ); 41 var 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 var 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 var wbte_set_block_checkout_values = function() { 132 133 let payment_method = ''; 134 let 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(){ 146 let prefix = $(this).attr('name').split('-').pop(); 147 shipping_method[prefix] = $(this).val(); 148 }); 149 } 150 151 /* Store the value to global variable to prevent future auto refresh blocking */ 152 WTSmartCouponOBJ.shipping_method = shipping_method; 153 WTSmartCouponOBJ.payment_method = payment_method; 154 155 156 /* Send ajax request to set the value */ 157 let order_summary_block = $('.wp-block-woocommerce-checkout-order-summary-block'); 158 wt_block_node( order_summary_block ); 159 160 $.ajax({ 161 type: "POST", 162 async: true, 163 url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_set_block_checkout_values', 164 data: { '_wpnonce': WTSmartCouponOBJ.nonces.public, 'payment_method': payment_method, 'shipping_method': shipping_method }, 165 dataType: 'json', 166 success:function( data ) { 167 wt_unblock_node( order_summary_block ); 168 }, 169 error:function() { 170 wt_unblock_node( order_summary_block ); 171 } 172 }); 173 174 /* Trigger checkout block refresh */ 175 setTimeout(function(){ 176 const checkout_value_updated_event = new CustomEvent("wbte_sc_checkout_value_updated", { 177 detail:{ 'payment_method' : payment_method, 'shipping_method': shipping_method } 178 }); 179 document.dispatchEvent(checkout_value_updated_event); 180 }, 1000); 181 182 } 183 184 185 /** 186 * Function from cart.js by woocommmerce 187 * @param {bool} preserve_notices 188 */ 189 var update_cart = function( preserve_notices ) { 190 var $form = $( '.woocommerce-cart-form' ); 191 wt_block_node( $form ); 192 wt_block_node( $( 'div.cart_totals' ) ); 193 194 195 196 // Make call to actual form post URL. 197 $.ajax( { 198 type: $form.attr( 'method' ), 199 url: $form.attr( 'action' ), 200 data: $form.serialize(), 201 dataType: 'html', 202 success: function( response ) { 203 update_wc_div( response, preserve_notices ); 204 }, 205 complete: function() { 206 wt_unblock_node( $form ); 207 wt_unblock_node( $( 'div.cart_totals' ) ); 208 } 209 } ); 210 } 211 212 213 /** 214 * 215 * @param {string} html_str 216 * @param {bool} preserve_notices 217 */ 218 var update_wc_div = function( html_str, preserve_notices ) { 219 var $html = $.parseHTML( html_str ); 220 var $new_form = $( '.woocommerce-cart-form', $html ); 221 var $new_totals = $( '.cart_totals', $html ); 222 var $notices = $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html ); 223 224 // No form, cannot do this. 225 if ( $( '.woocommerce-cart-form' ).length === 0 ) { 226 window.location.href = window.location.href; 227 return; 228 } 229 230 // Remove errors 231 if ( ! preserve_notices ) { 232 $( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); 233 } 234 235 if ( $new_form.length === 0 ) {
236 // If the checkout is also displayed on this page, trigger reload instead. 237 if ( $( '.woocommerce-checkout' ).length ) { 238 window.location.href = window.location.href; 239 return; 240 } 241 242 // No items to display now! Replace all cart content. 243 var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' ); 244 $( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html ); 245 246 // Display errors 247 if ( $notices.length > 0 ) { 248 show_notice( $notices ); 249 } 250 } else { 251 // If the checkout is also displayed on this page, trigger update event. 252 if ( $( '.woocommerce-checkout' ).length ) { 253 $( document.body ).trigger( 'update_checkout' ); 254 } 255 256 $( '.woocommerce-cart-form' ).replaceWith( $new_form ); 257 $( '.woocommerce-cart-form' ).find( ':input[name="update_cart"]' ).prop( 'disabled', true ); 258 259 if ( $notices.length > 0 ) { 260 show_notice( $notices ); 261 } 262 263 update_cart_totals_div( $new_totals ); 264 } 265 266 $( document.body ).trigger( 'updated_wc_div' ); 267 }; 268 269 270 /** 271 * Function from woocmmerce cart.js 272 * @param {string} html_str 273 */ 274 var update_cart_totals_div = function( html_str ) { 275 $( '.cart_totals' ).replaceWith( html_str ); 276 $( document.body ).trigger( 'updated_cart_totals' ); 277 }; 278 279 280 281 /** 282 * function from cart.js by wooocommerce 283 * @param { jQuery object } node 284 */ 285 var wt_block_node = function( node ) { 286 287 node.addClass( 'processing' ); 288 289 if(typeof $.fn.block === 'function') 290 { 291 node.block({ 292 message: null, 293 overlayCSS: { 294 background: '#fff', 295 opacity: 0.6 296 } 297 }); 298 } 299 } 300 window.wbte_sc_block_node = wt_block_node; 301 302 /** 303 * function from cart.js by wooocommerce 304 * @param {jQuery object} $node 305 */ 306 var wt_unblock_node = function( node ) { 307 308 node.removeClass( 'processing' ); 309 310 if(typeof $.fn.unblock === 'function') 311 { 312 node.unblock(); 313 } 314 }; 315 window.wbte_sc_unblock_node = wt_unblock_node; 316 317 318 var show_notice = function( html_element, $target ) { 319 if ( ! $target ) { 320 $target = $( '.woocommerce-notices-wrapper:first' ) || $( '.cart-empty' ).closest( '.woocommerce' ) || $( '.woocommerce-cart-form' ); 321 } 322 $target.prepend( html_element ); 323 }; 324 325});
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.