Listeners for custom “refresh button” event

This commit is contained in:
Philipp Stracker 2024-06-26 17:57:45 +02:00
parent 25c5ef2e9e
commit 5ed2f37bd4
No known key found for this signature in database
2 changed files with 16 additions and 14 deletions

View file

@ -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(