From 8fa2e624aa83fbaff595b751e8aa07587a1535f0 Mon Sep 17 00:00:00 2001 From: mtworoz Date: Wed, 23 Oct 2024 11:00:33 +0200 Subject: [PATCH] poprawka selektora js dla koszyka podzielonego --- assets/js/edd-checkout-global.js | 15 +++++++-------- assets/js/edd-checkout-global.min.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/assets/js/edd-checkout-global.js b/assets/js/edd-checkout-global.js index b12f122aab..dd18e09626 100644 --- a/assets/js/edd-checkout-global.js +++ b/assets/js/edd-checkout-global.js @@ -5,14 +5,14 @@ window.EDD_Checkout = (function($) { $form, $edd_cart_amount, before_discount, - $checkout_form_wrap; + $content_wrap; function init() { $body = $(document.body); $form = $("#edd_purchase_form"); $edd_cart_amount = $('.edd_cart_amount'); before_discount = $edd_cart_amount.text(); - $checkout_form_wrap = $('#edd_checkout_form_wrap'); + $content_wrap = $("#content"); // Update state/province field on checkout page $body.on('change', '#edd_cc_address input.card_state, #edd_cc_address select', update_state_field); @@ -37,19 +37,19 @@ window.EDD_Checkout = (function($) { }); // Validate and apply a discount - $checkout_form_wrap.on('click', '.edd-apply-discount', apply_discount); + $content_wrap.on('click', '.edd-apply-discount', apply_discount); // Prevent the checkout form from submitting when hitting Enter in the discount field - $checkout_form_wrap.on('keypress', '#edd-discount', function (event) { + $content_wrap.on('keypress', '#edd-discount', function (event) { if (event.keyCode == '13') { return false; } }); // Apply the discount when hitting Enter in the discount field instead - $checkout_form_wrap.on('keyup', '#edd-discount', function (event) { + $content_wrap.on('keyup', '#edd-discount', function (event) { if (event.keyCode == '13') { - $checkout_form_wrap.find('.edd-apply-discount').trigger('click'); + $content_wrap.find('.edd-apply-discount').trigger('click'); } }); @@ -187,7 +187,6 @@ window.EDD_Checkout = (function($) { } function apply_discount(event) { - event.preventDefault(); var $this = $(this), @@ -223,7 +222,7 @@ window.EDD_Checkout = (function($) { $('.edd_cart_amount').each(function() { $(this).text(discount_response.total); }); - $('#edd-discount', $checkout_form_wrap ).val(''); + $('#edd-discount', $content_wrap ).val(''); recalculate_taxes(); diff --git a/assets/js/edd-checkout-global.min.js b/assets/js/edd-checkout-global.min.js index a03d0771d3..93b9cda267 100644 --- a/assets/js/edd-checkout-global.min.js +++ b/assets/js/edd-checkout-global.min.js @@ -1 +1 @@ -window.EDD_Checkout=function(e){"use strict";var d,t,a,n,o;function c(){var a=e(this);if("card_state"!=a.attr("id")){var n={action:"edd_get_shop_states",country:a.val(),field_name:"card_state"};e.ajax({type:"POST",data:n,url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(a){"nostates"==e.trim(a)?t.find('input[name="card_state"], select[name="card_state"]').replaceWith(''):t.find('input[name="card_state"], select[name="card_state"]').replaceWith(a),d.trigger("edd_cart_billing_address_updated",[a])}}).fail(function(e){window.console&&window.console.log&&console.log(e)}).done(function(e){s()})}else s();return!1}function s(t){if("1"==edd_global_vars.taxes_enabled){var a=e("#edd_cc_address");t||(t=a.find("#card_state").val());var n={action:"edd_recalculate_taxes",billing_country:a.find("#billing_country").val(),state:t};e.ajax({type:"POST",data:n,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){e("#edd_checkout_cart_form").replaceWith(t.html),e(".edd_cart_amount").html(t.total);var a={};a.postdata=n,a.response=t,d.trigger("edd_taxes_recalculated",[a])}}).fail(function(e){window.console&&window.console.log&&(console.log(e),d.trigger("edd_taxes_recalculated",[tax_data]))})}}function i(t){t.preventDefault(),e(this);var a=e("#edd-discount").val(),n=e("#edd-discount-loader");if(""==a||a==edd_global_vars.enter_discount)return!1;var c={action:"edd_apply_discount",code:a,form:e("#edd_purchase_form").serialize()};return e("#edd-discount-error-wrap").html("").hide(),n.show(),e.ajax({type:"POST",data:c,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){if(t){if("valid"==t.msg){e(".edd_cart_discount").html(t.html),e(".edd_cart_discount_row").show(),e(".edd_cart_amount").each(function(){e(this).text(t.total)}),e("#edd-discount",o).val(""),s();var a=e("#edd_cc_fields .edd-input, #edd_cc_fields .edd-select,#edd_cc_address .edd-input, #edd_cc_address .edd-select,#edd_payment_mode_select .edd-input, #edd_payment_mode_select .edd-select");"0.00"==t.total_plain?(e("#edd_cc_fields,#edd_cc_address,#edd_payment_mode_select,.secure_payments").slideUp(),a.removeAttr("required"),e('input[name="edd-gateway"]').val("manual"),edd_load_gateway("manual")):(a.attr("required","required"),e("#edd_cc_fields,#edd_cc_address,#edd_payment_mode_select,.secure_payments").slideDown(),edd_load_gateway(e("#edd-gateway option:selected, input.edd-gateway:checked").val())),d.trigger("edd_discount_applied",[t])}else e("#edd-discount-error-wrap").html(''+t.msg+""),e("#edd-discount-error-wrap").show(),d.trigger("edd_discount_invalid",[t])}else window.console&&window.console.log&&console.log(t),d.trigger("edd_discount_failed",[t]);n.hide()}}).fail(function(e){window.console&&window.console.log&&console.log(e)}),!1}function r(t){var a={action:"edd_remove_discount",code:e(this).data("code")};return e.ajax({type:"POST",data:a,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){0===t.previous_total&&(e("#edd_payment_mode_select,.secure_payments").slideDown(),edd_load_gateway(e("#edd-gateway option:selected, input.edd-gateway:checked").val()));var a="0"+edd_global_vars.decimal_separator+"00";e(".edd_cart_amount").each(function(){(edd_global_vars.currency_sign+a==e(this).text()||a+edd_global_vars.currency_sign==e(this).text())&&window.location.reload(),e(this).text(t.total)}),e(".edd_cart_discount").html(t.html),t.discounts||e(".edd_cart_discount_row").hide(),s(),e("#edd_cc_fields,#edd_cc_address").slideDown(),d.trigger("edd_discount_removed",[t])}}).fail(function(e){window.console&&window.console.log&&console.log(e)}),!1}function l(t){var a=e(this),n=a.val(),o=a.data("key"),c=a.closest(".edd_cart_item").data("download-id"),s=a.parent().find('input[name="edd-cart-download-'+o+'-options"]').val();return e.ajax({type:"POST",data:{action:"edd_update_quantity",quantity:n,download_id:c,options:s},dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){e(".edd_cart_subtotal_amount").each(function(){e(this).text(t.subtotal)}),e(".edd_cart_tax_amount").each(function(){e(this).text(t.taxes)}),e(".edd_cart_amount").each(function(){e(this).text(t.total),d.trigger("edd_quantity_updated",[t])})}}).fail(function(e){window.console&&window.console.log&&console.log(e)}),!1}return{init:function s(){d=e(document.body),t=e("#edd_purchase_form"),n=(a=e(".edd_cart_amount")).text(),o=e("#edd_checkout_form_wrap"),d.on("change","#edd_cc_address input.card_state, #edd_cc_address select",c),d.on("keyup change",".edd-do-validate .card-number",function(){var d,t;d=e(this),t=d,t.validateCreditCard(function(d){var a=e(".card-type");null==d.card_type?(a.removeClass().addClass("off card-type"),t.removeClass("valid"),t.addClass("error")):(a.removeClass("off"),a.addClass(d.card_type.name),d.length_valid&&d.luhn_valid?(t.addClass("valid"),t.removeClass("error")):(t.removeClass("valid"),t.addClass("error")))})}),d.on("submit","#edd_payment_mode",function(){if(0==e("#edd-gateway option:selected").val())return alert(edd_global_vars.no_gateway),!1}),d.on("click","#edd_payment_mode_select input",function(){e("#edd_payment_mode_select label.edd-gateway-option-selected").removeClass("edd-gateway-option-selected"),e("#edd_payment_mode_select input:checked").parent().addClass("edd-gateway-option-selected")}),o.on("click",".edd-apply-discount",i),o.on("keypress","#edd-discount",function(e){if("13"==e.keyCode)return!1}),o.on("keyup","#edd-discount",function(e){"13"==e.keyCode&&o.find(".edd-apply-discount").trigger("click")}),d.on("click",".edd_discount_remove",r),d.on("click",".edd_discount_link",function(d){d.preventDefault(),e(".edd_discount_link").parent().hide(),e("#edd-discount-code-wrap").show().find("#edd-discount").focus()}),d.find("#edd-discount-code-wrap").hide(),d.find("#edd_show_discount").show(),d.on("change",".edd-item-quantity",l),d.on("click",".edd-amazon-logout #Logout",function(e){e.preventDefault(),amazon.Login.logout(),window.location=edd_amazon.checkoutUri})},recalculate_taxes:s}}(window.jQuery),window.jQuery(document).ready(EDD_Checkout.init); \ No newline at end of file +window.EDD_Checkout=function(e){"use strict";var d,t,a,o;function n(){var a=e(this);if("card_state"!=a.attr("id")){var o={action:"edd_get_shop_states",country:a.val(),field_name:"card_state"};e.ajax({type:"POST",data:o,url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(a){if("nostates"==e.trim(a)){t.find('input[name="card_state"], select[name="card_state"]').replaceWith('')}else t.find('input[name="card_state"], select[name="card_state"]').replaceWith(a);d.trigger("edd_cart_billing_address_updated",[a])}}).fail((function(e){window.console&&window.console.log&&console.log(e)})).done((function(e){c()}))}else c();return!1}function c(t){if("1"==edd_global_vars.taxes_enabled){var a=e("#edd_cc_address");t||(t=a.find("#card_state").val());var o={action:"edd_recalculate_taxes",billing_country:a.find("#billing_country").val(),state:t};e.ajax({type:"POST",data:o,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){e("#edd_checkout_cart_form").replaceWith(t.html),e(".edd_cart_amount").html(t.total);var a=new Object;a.postdata=o,a.response=t,d.trigger("edd_taxes_recalculated",[a])}}).fail((function(e){window.console&&window.console.log&&(console.log(e),d.trigger("edd_taxes_recalculated",[tax_data]))}))}}function s(t){t.preventDefault();e(this);var a=e("#edd-discount").val(),n=e("#edd-discount-loader");if(""==a||a==edd_global_vars.enter_discount)return!1;var s={action:"edd_apply_discount",code:a,form:e("#edd_purchase_form").serialize()};return e("#edd-discount-error-wrap").html("").hide(),n.show(),e.ajax({type:"POST",data:s,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){if(t)if("valid"==t.msg){e(".edd_cart_discount").html(t.html),e(".edd_cart_discount_row").show(),e(".edd_cart_amount").each((function(){e(this).text(t.total)})),e("#edd-discount",o).val(""),c();var a=e("#edd_cc_fields .edd-input, #edd_cc_fields .edd-select,#edd_cc_address .edd-input, #edd_cc_address .edd-select,#edd_payment_mode_select .edd-input, #edd_payment_mode_select .edd-select");"0.00"==t.total_plain?(e("#edd_cc_fields,#edd_cc_address,#edd_payment_mode_select,.secure_payments").slideUp(),a.removeAttr("required"),e('input[name="edd-gateway"]').val("manual"),edd_load_gateway("manual")):(a.attr("required","required"),e("#edd_cc_fields,#edd_cc_address,#edd_payment_mode_select,.secure_payments").slideDown(),edd_load_gateway(e("#edd-gateway option:selected, input.edd-gateway:checked").val())),d.trigger("edd_discount_applied",[t])}else e("#edd-discount-error-wrap").html(''+t.msg+""),e("#edd-discount-error-wrap").show(),d.trigger("edd_discount_invalid",[t]);else window.console&&window.console.log&&console.log(t),d.trigger("edd_discount_failed",[t]);n.hide()}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}function i(t){var a={action:"edd_remove_discount",code:e(this).data("code")};return e.ajax({type:"POST",data:a,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){0===t.previous_total&&(e("#edd_payment_mode_select,.secure_payments").slideDown(),edd_load_gateway(e("#edd-gateway option:selected, input.edd-gateway:checked").val()));var a="0"+edd_global_vars.decimal_separator+"00";e(".edd_cart_amount").each((function(){edd_global_vars.currency_sign+a!=e(this).text()&&a+edd_global_vars.currency_sign!=e(this).text()||window.location.reload(),e(this).text(t.total)})),e(".edd_cart_discount").html(t.html),t.discounts||e(".edd_cart_discount_row").hide(),c(),e("#edd_cc_fields,#edd_cc_address").slideDown(),d.trigger("edd_discount_removed",[t])}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}function l(t){var a=e(this),o=a.val(),n=a.data("key"),c={action:"edd_update_quantity",quantity:o,download_id:a.closest(".edd_cart_item").data("download-id"),options:a.parent().find('input[name="edd-cart-download-'+n+'-options"]').val()};return e.ajax({type:"POST",data:c,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){e(".edd_cart_subtotal_amount").each((function(){e(this).text(t.subtotal)})),e(".edd_cart_tax_amount").each((function(){e(this).text(t.taxes)})),e(".edd_cart_amount").each((function(){e(this).text(t.total),d.trigger("edd_quantity_updated",[t])}))}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}return{init:function(){d=e(document.body),t=e("#edd_purchase_form"),a=e(".edd_cart_amount"),a.text(),o=e("#content"),d.on("change","#edd_cc_address input.card_state, #edd_cc_address select",n),d.on("keyup change",".edd-do-validate .card-number",(function(){var d,t;d=e(this),(t=d).validateCreditCard((function(d){var a=e(".card-type");null==d.card_type?(a.removeClass().addClass("off card-type"),t.removeClass("valid"),t.addClass("error")):(a.removeClass("off"),a.addClass(d.card_type.name),d.length_valid&&d.luhn_valid?(t.addClass("valid"),t.removeClass("error")):(t.removeClass("valid"),t.addClass("error")))}))})),d.on("submit","#edd_payment_mode",(function(){if(0==e("#edd-gateway option:selected").val())return alert(edd_global_vars.no_gateway),!1})),d.on("click","#edd_payment_mode_select input",(function(){e("#edd_payment_mode_select label.edd-gateway-option-selected").removeClass("edd-gateway-option-selected"),e("#edd_payment_mode_select input:checked").parent().addClass("edd-gateway-option-selected")})),o.on("click",".edd-apply-discount",s),o.on("keypress","#edd-discount",(function(e){if("13"==e.keyCode)return!1})),o.on("keyup","#edd-discount",(function(e){"13"==e.keyCode&&o.find(".edd-apply-discount").trigger("click")})),d.on("click",".edd_discount_remove",i),d.on("click",".edd_discount_link",(function(d){d.preventDefault(),e(".edd_discount_link").parent().hide(),e("#edd-discount-code-wrap").show().find("#edd-discount").focus()})),d.find("#edd-discount-code-wrap").hide(),d.find("#edd_show_discount").show(),d.on("change",".edd-item-quantity",l),d.on("click",".edd-amazon-logout #Logout",(function(e){e.preventDefault(),amazon.Login.logout(),window.location=edd_amazon.checkoutUri}))},recalculate_taxes:c}}(window.jQuery),window.jQuery(document).ready(EDD_Checkout.init); \ No newline at end of file