From 35f3b00cb9478c008bb0d116a1bd943486663d29 Mon Sep 17 00:00:00 2001 From: jonas-hoebenreich Date: Thu, 28 Nov 2024 23:58:17 +0100 Subject: [PATCH] fix: fee recovery checkbox not being applied Update wcdp.js, wcdp.min.js, and 2 more files... --- assets/js/wcdp.js | 19 ++++++++++--------- assets/js/wcdp.min.js | 2 +- readme.txt | 7 +++++-- wc-donation-platform.php | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/assets/js/wcdp.js b/assets/js/wcdp.js index 918743ef..f01e44f7 100644 --- a/assets/js/wcdp.js +++ b/assets/js/wcdp.js @@ -1,4 +1,11 @@ jQuery( function( $ ) { + $(document).on('change', '#wcdp_fee_recovery, input[name="payment_method"]', function () { + console.log('triggerCheckoutUpdate'); + if ($(this).is('#wcdp_fee_recovery') || $('#wcdp_fee_recovery').prop('checked')) { + triggerCheckoutUpdate(); + } + }); + if (!document.querySelector('#wcdp')) return; let currentFormData; @@ -76,7 +83,7 @@ jQuery( function( $ ) { /** * Handle submit of add to cart form */ - $('#wcdp-ajax-send').on('submit', function(e){ + $('#wcdp-ajax-send')?.on('submit', function(e){ e.preventDefault(); const serialized = $("#wcdp-ajax-send").serialize(); if (currentFormData != serialized) { @@ -91,7 +98,7 @@ jQuery( function( $ ) { * Submit step 1 form automatically for style 3 */ let time = 0; - $( '.wcdp-body > #wcdp-ajax-send' ).on('input blur keyup paste change', function (){ + $( '.wcdp-body > #wcdp-ajax-send' )?.on('input blur keyup paste change', function (){ if (currentFormData != $("#wcdp-ajax-send").serialize()) { time++; currentFormData = $("#wcdp-ajax-send").serialize(); @@ -109,7 +116,7 @@ jQuery( function( $ ) { */ let expresstime = 0; let currentprice = 0; - $( '.wcdp-body' ).on('input blur keyup paste change load', function (){ + $( '.wcdp-body' )?.on('input blur keyup paste change load', function (){ const button = document.querySelector('.wcdp-body .single_add_to_cart_button'); const form = document.querySelector('#wcdp-get-send'); if (button && form && form.checkValidity()) { @@ -270,12 +277,6 @@ jQuery( function( $ ) { setTimeout(() => $('body').trigger('update_checkout'), delay); } - $(document).on('change', '#wcdp_fee_recovery, input[name="payment_method"]', function () { - if ($(this).is('#wcdp_fee_recovery') || $('#wcdp_fee_recovery').prop('checked')) { - triggerCheckoutUpdate(); - } - }); - //copy value of range slider $( '#wcdp-range' )?.on('input', function () { const range = $( '#wcdp-range' ); diff --git a/assets/js/wcdp.min.js b/assets/js/wcdp.min.js index 56c43786..28d41b22 100755 --- a/assets/js/wcdp.min.js +++ b/assets/js/wcdp.min.js @@ -1 +1 @@ -jQuery(function(d){if(document.querySelector("#wcdp")){let c,e=(d("#wcdp-ajax-send").on("submit",function(e){e.preventDefault();e=d("#wcdp-ajax-send").serialize();c!=e?(c=e,r("2")):l(2)}),0),a=(d(".wcdp-body > #wcdp-ajax-send").on("input blur keyup paste change",function(){c!=d("#wcdp-ajax-send").serialize()&&(e++,c=d("#wcdp-ajax-send").serialize(),setTimeout(function(){0==--e&&r()},1300))}),0),o=0,n=(d(".wcdp-body").on("input blur keyup paste change load",function(){let e=document.querySelector(".wcdp-body .single_add_to_cart_button");var t=document.querySelector("#wcdp-get-send");e&&t&&t.checkValidity()?e.classList.remove("disabled"):e&&e.classList.add("disabled"),d(".wcdp-express-amount").val(d("#wcdp-donation-amount").val()),a++,setTimeout(function(){0==--a&&o!=d("#wcdp-donation-amount").val()&&(o=d("#wcdp-donation-amount").val(),d(document.body).trigger("woocommerce_variation_has_changed"),e)&&e.classList.toggle("wcdp_price_changed")},500)}),1),t=(d(".wcdp-form .wcdp-button, .wcdp-step").click(function(){var e,t=d(this).attr("value");1!=n?l(t):1!=t&&p("#wcdp-ajax-send")&&(e=d("#wcdp-ajax-send").serialize(),(c!=e?(c=e,r):l)(t))}),10);d(document).ready(function(){d(".wcdp-loader")?.hide(),d(".wc-donation-platform")?.css({visibility:"visible","animation-name":"wcdp-appear-animation","animation-duration":"1s"}),h(!1);try{0!=d("#wcdp-donation-amount")?.val()&&d("#wcdp-ajax-send")?.trigger("change"),d(".wcdp-choose-donation")[0].checkValidity()&&(c=d("#wcdp-ajax-send")?.serialize(),r()),d("form.woocommerce-checkout select")?.selectWoo()}finally{d("#wcdp-ajax-send,.wcdp_options")?.trigger("change"),setTimeout(u,t)}}),window.onhashchange=function(){h(!1)},d(".wcdp-modal-open")?.click(function(){h(!0)}),d(document).on("keypress","input",function(e){"Escape"==e.key&&w()}),d(".wcdp-modal-close")?.click(w);var i=!1;function r(t){var e,c;p("#wcdp-ajax-send")&&(d("#wcdp-spinner").show(),d("#wcdp-ajax-button").hide(),c=(e=d("#wcdp-ajax-send")).serialize(),d.ajax({type:"POST",url:e.attr("action"),data:c}).done(function(e){!0===e.success?(d(".woocommerce-error").remove(),d("body").trigger("update_checkout"),d("#wcdp-ajax-button").show(),d("#wcdp-spinner").hide(),e.recurring?(d("#createaccount").prop("checked",!0).trigger("change"),d(".create-account:has(#createaccount)").hide()):d(".create-account:has(#createaccount)").show(),l(t)):s(e.message,e.reload,e.newParams)}).fail(function(){d("#wcdp-spinner").hide(),s(d(".wcdp-choose-donation").attr("wcdp-error-default"))}))}function p(e){var t=d("#variation_id");try{return d(e)[0].reportValidity()&&(0===t.length||""!=t.attr("value"))}catch(e){}}function s(e="An unexpected error occurred. Please reload the page and try again. If the problem persists, please contact our support team.",t=!0,a=!1){if(t||d("#wcdp-ajax-button").show(),a){alert(e);let c=new URL(window.location.href);Object.entries(a).forEach(([e,t])=>c.searchParams.set(e,t)),window.location.href=c.toString()}d("#wcdp-spinner").hide(),d("#wcdp-ajax-error").remove(),d("form.checkout.woocommerce-checkout").prepend(''),d("#wcdp-ajax-error li").text(e)}function l(e){var t=d(":root")[0];switch(t.style.setProperty("--wcdp-step-2","var(--wcdp-main)"),t.style.setProperty("--wcdp-step-3","var(--wcdp-main)"),e){case"3":d("#wcdp-step-2").show(),d("form.checkout").find(".input-text:visible, select:visible, input:checkbox:visible").trigger("validate"),0d("body").trigger("update_checkout"),400)}),d("#wcdp-range")?.on("input",function(){var e=d("#wcdp-range"),t=d("#wcdp-donation-amount");t.val(e.val()),e.val()==e.attr("max")&&t.select()}),d(".wcdp-amount-range-field")?.on("input",function(){d("#wcdp-range")?.val(d("#wcdp-donation-amount")?.val())}),d("#wcdp-donation-amount")?.on("change",function(){var e="#wcdp_value_"+d("#wcdp-donation-amount")?.val()?.replace(/./g,"-");(0==d(e)?.length?d("#wcdp_value_other"):d(e))?.prop("checked",!0)}),d("#wcdp_value_other")?.click(function(){d("#wcdp-donation-amount")?.focus()}),d(".wcdp-choose-donation")?.on("change",function(){d(".wcdp_su input")?.each(function(){0==d("#"+this.name+' option[value="'+this.value+'"]').length?this.setAttribute("disabled","true"):this.removeAttribute("disabled")})})}}); +jQuery(function(d){if(d(document).on("change",'#wcdp_fee_recovery, input[name="payment_method"]',function(){console.log("triggerCheckoutUpdate"),(d(this).is("#wcdp_fee_recovery")||d("#wcdp_fee_recovery").prop("checked"))&&setTimeout(()=>d("body").trigger("update_checkout"),400)}),document.querySelector("#wcdp")){let c,e=(d("#wcdp-ajax-send")?.on("submit",function(e){e.preventDefault();e=d("#wcdp-ajax-send").serialize();c!=e?(c=e,r("2")):l(2)}),0),a=(d(".wcdp-body > #wcdp-ajax-send")?.on("input blur keyup paste change",function(){c!=d("#wcdp-ajax-send").serialize()&&(e++,c=d("#wcdp-ajax-send").serialize(),setTimeout(function(){0==--e&&r()},1300))}),0),o=0,n=(d(".wcdp-body")?.on("input blur keyup paste change load",function(){let e=document.querySelector(".wcdp-body .single_add_to_cart_button");var t=document.querySelector("#wcdp-get-send");e&&t&&t.checkValidity()?e.classList.remove("disabled"):e&&e.classList.add("disabled"),d(".wcdp-express-amount").val(d("#wcdp-donation-amount").val()),a++,setTimeout(function(){0==--a&&o!=d("#wcdp-donation-amount").val()&&(o=d("#wcdp-donation-amount").val(),d(document.body).trigger("woocommerce_variation_has_changed"),e)&&e.classList.toggle("wcdp_price_changed")},500)}),1),t=(d(".wcdp-form .wcdp-button, .wcdp-step").click(function(){var e,t=d(this).attr("value");1!=n?l(t):1!=t&&p("#wcdp-ajax-send")&&(e=d("#wcdp-ajax-send").serialize(),(c!=e?(c=e,r):l)(t))}),10);d(document).ready(function(){d(".wcdp-loader")?.hide(),d(".wc-donation-platform")?.css({visibility:"visible","animation-name":"wcdp-appear-animation","animation-duration":"1s"}),h(!1);try{0!=d("#wcdp-donation-amount")?.val()&&d("#wcdp-ajax-send")?.trigger("change"),d(".wcdp-choose-donation")[0].checkValidity()&&(c=d("#wcdp-ajax-send")?.serialize(),r()),d("form.woocommerce-checkout select")?.selectWoo()}finally{d("#wcdp-ajax-send,.wcdp_options")?.trigger("change"),setTimeout(u,t)}}),window.onhashchange=function(){h(!1)},d(".wcdp-modal-open")?.click(function(){h(!0)}),d(document).on("keypress","input",function(e){"Escape"==e.key&&w()}),d(".wcdp-modal-close")?.click(w);var i=!1;function r(t){var e,c;p("#wcdp-ajax-send")&&(d("#wcdp-spinner").show(),d("#wcdp-ajax-button").hide(),c=(e=d("#wcdp-ajax-send")).serialize(),d.ajax({type:"POST",url:e.attr("action"),data:c}).done(function(e){!0===e.success?(d(".woocommerce-error").remove(),d("body").trigger("update_checkout"),d("#wcdp-ajax-button").show(),d("#wcdp-spinner").hide(),e.recurring?(d("#createaccount").prop("checked",!0).trigger("change"),d(".create-account:has(#createaccount)").hide()):d(".create-account:has(#createaccount)").show(),l(t)):s(e.message,e.reload,e.newParams)}).fail(function(){d("#wcdp-spinner").hide(),s(d(".wcdp-choose-donation").attr("wcdp-error-default"))}))}function p(e){var t=d("#variation_id");try{return d(e)[0].reportValidity()&&(0===t.length||""!=t.attr("value"))}catch(e){}}function s(e="An unexpected error occurred. Please reload the page and try again. If the problem persists, please contact our support team.",t=!0,a=!1){if(t||d("#wcdp-ajax-button").show(),a){alert(e);let c=new URL(window.location.href);Object.entries(a).forEach(([e,t])=>c.searchParams.set(e,t)),window.location.href=c.toString()}d("#wcdp-spinner").hide(),d("#wcdp-ajax-error").remove(),d("form.checkout.woocommerce-checkout").prepend(''),d("#wcdp-ajax-error li").text(e)}function l(e){var t=d(":root")[0];switch(t.style.setProperty("--wcdp-step-2","var(--wcdp-main)"),t.style.setProperty("--wcdp-step-3","var(--wcdp-main)"),e){case"3":d("#wcdp-step-2").show(),d("form.checkout").find(".input-text:visible, select:visible, input:checkbox:visible").trigger("validate"),0