diff --git a/modules/ppcp-applepay/resources/js/boot.js b/modules/ppcp-applepay/resources/js/boot.js index b4b19cde5..4bc5eaf8b 100644 --- a/modules/ppcp-applepay/resources/js/boot.js +++ b/modules/ppcp-applepay/resources/js/boot.js @@ -1,6 +1,7 @@ import {loadCustomScript} from "@paypal/paypal-js"; import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading"; import ApplepayManager from "./ApplepayManager"; +import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce'; (function ({ buttonConfig, @@ -15,19 +16,19 @@ import ApplepayManager from "./ApplepayManager"; manager.init(); }; - jQuery(document.body).on('updated_cart_totals updated_checkout', () => { + const refresh = debounce(function() { if (manager) { manager.reinit(); } - }); + }, 50); + + jQuery(document).on('ppcp_refresh_payment_buttons', refresh); + + jQuery(document.body).on('updated_cart_totals updated_checkout', refresh); // Use set timeout as it's unnecessary to refresh upon Minicart initial render. setTimeout(() => { - jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => { - if (manager) { - manager.reinit(); - } - }); + jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', refresh); }, 1000); document.addEventListener( diff --git a/modules/ppcp-googlepay/resources/js/boot.js b/modules/ppcp-googlepay/resources/js/boot.js index f90655d5c..c26267d14 100644 --- a/modules/ppcp-googlepay/resources/js/boot.js +++ b/modules/ppcp-googlepay/resources/js/boot.js @@ -1,6 +1,7 @@ import {loadCustomScript} from "@paypal/paypal-js"; import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading"; import GooglepayManager from "./GooglepayManager"; +import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce'; (function ({ buttonConfig, @@ -15,19 +16,19 @@ import GooglepayManager from "./GooglepayManager"; manager.init(); }; - jQuery(document.body).on('updated_cart_totals updated_checkout', () => { + const refresh = debounce(function() { if (manager) { manager.reinit(); } - }); + }, 50); + + jQuery(document).on('ppcp_refresh_payment_buttons', refresh); + + jQuery(document.body).on('updated_cart_totals updated_checkout', refresh); // Use set timeout as it's unnecessary to refresh upon Minicart initial render. setTimeout(() => { - jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => { - if (manager) { - manager.reinit(); - } - }); + jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', refresh); }, 1000); document.addEventListener(