mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Listeners for custom “refresh button” event
This commit is contained in:
parent
25c5ef2e9e
commit
5ed2f37bd4
2 changed files with 16 additions and 14 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue