1/* 2 * Hooks into payment methods radio buttons 3 * 4 * depends on woocommerce.js 5 */ 6jQuery(function($) 7{ 8 if( $('body').hasClass( 'woocommerce-order-pay' ) ) 9 { 10 const pay_order_page = $('#add_fee_info_pay'); 11 12 if( pay_order_page.length > 0 ) 13 { 14 // bugfix in WC core - ensure, that the payment gateway for the order is selected - not the first one as in core 15 var gateway = pay_order_page.attr('add_fee_paymethod'); 16 var gateway_sel = $('#payment').find("input[name='payment_method']:checked").attr('value'); 17 18 if( gateway !== gateway_sel ) 19 { 20 $(".payment_methods input[name='payment_method'][value='" + gateway + "']").attr( "checked", true ); 21 } 22 23 var fixed_gateway = pay_order_page.attr('add_fee_fixed_gateway'); 24 if( fixed_gateway === 'yes' ) 25 { 26 $('body').find('form#order_review .payment_methods li').each(function () 27 { 28 var radio = $(this).find('input.input-radio'); 29 if( ( radio.length > 0 ) && ( ! radio.is(':checked') ) ) 30 { 31 $(this).remove(); 32 } 33 return; 34 }); 35 } 36 37 $( '.payment_methods input.input-radio' ).on( 'change', function() 38 { 39 $('#addfeeerror').remove(); 40 41 var selector = '.woocommerce'; 42 $(selector).block( { 43 message: null, 44 overlayCSS: { 45 background: '#fff url(' + add_fee_vars.add_fee_loader + ') no-repeat center', 46 backgroundSize: '16px 16px', 47 opacity: 0.6 48 } 49 } ); 50 51 var senddata = { 52 action: pay_order_page.attr('add_fee_action'), 53 add_fee_order: pay_order_page.attr('add_fee_order'), 54 add_fee_pay: pay_order_page.attr('add_fee_pay'), 55 add_fee_paymethod: $(this).attr('value'), 56 add_fee_key: pay_order_page.attr('add_fee_key'), 57 add_fee_nonce: add_fee_vars.add_fee_nonce 58 }; 59 60 $.ajax({ 61 type: "POST", 62 url: add_fee_vars.add_fee_ajaxurl, 63 dataType: 'json', 64 cache: false, 65 data: senddata, 66 success : function(response, textStatus, jqXHR){ 67 if(response.success) 68 { 69 if(response.recalc) 70 { 71 $('.shop_table').replaceWith(response.message); 72 $('#payment .form-row').show(); 73 } 74 } 75 else 76 { 77 $('#payment .form-row').hide(); 78 alert(response.alert); 79 $('#order_review').before(response.message); 80 }; 81 }, 82 error: function(testObj){ 83 $('#payment .form-row').hide(); 84 alert(add_fee_vars.alert_ajax_error); 85 }, 86 complete: function(test){ 87 $(selector).unblock(); 88 } 89 }); 90 91 }); 92 93 // @since 3.2.3: fixes problem with payment method N/A for new created orders in backend 94 setTimeout( function() 95 { 96 $( '#payment' ).find( "input[name='payment_method']:checked" ).trigger( 'change' ); 97 }, 100 ); 98 99 return false; 100 } 101 } 102 103 /** 104 * These 2 variables are a try for a core fix that resets the payment gateway to the preselected 105 * 106 */ 107// var wc_add_fees_payment_selected_id = null; 108// var wc_add_fees_payment_ignore_change = false; 109 110 // standard checkout page 111 $('.woocommerce').on('change', '.payment_methods .input-radio', function() 112 { 113// if( wc_add_fees_payment_ignore_change ) 114// { 115// return; 116// } 117 118// wc_add_fees_payment_selected_id = $(this).attr('id'); 119 120 121 let current_selected_id = $( '.payment_methods .input-radio:checked' ).attr('id'); 122 let changed_id = $(this).attr('id'); 123 124 if( changed_id == current_selected_id ) 125 { 126 $('body').trigger('update_checkout'); 127 } 128 else 129 { 130 // added 5.2.2 - fixes a problem when checkbox change is triggered programmatically by 3rd party plugin like WooCommerce Square 131 setTimeout( function() 132 { 133 $('body').trigger('update_checkout'); 134 }, 100 ); 135 } 136 }); 137 138 /** 139 * This is a try for a fix in wc core - can be removed completely when core is fixed 140 * 141 * added with ??? 142 * removed with 5.2.2 143 */ 144// $( document.body ).on( 'updated_checkout', function() 145// { 146// if( wc_add_fees_payment_selected_id === null ) 147// { 148// return; 149// } 150// 151// return; 152// 153// var new_selected = $( '.payment_methods .input-radio:checked'); 154// 155// if( wc_add_fees_payment_selected_id === new_selected.attr('id') ) 156// { 157// return; 158// } 159// 160// wc_add_fees_payment_ignore_change = true; 161// 162// $( '.payment_methods #' + wc_add_fees_payment_selected_id ).prop("checked", true ); 163// 164// wc_add_fees_payment_ignore_change = false;
165// wc_add_fees_payment_selected_id = null; 166// }); 167 168});
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.