mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Sync gateway visibility via custom event
This commit is contained in:
parent
490cd1958b
commit
0888c696ff
2 changed files with 65 additions and 25 deletions
|
@ -68,6 +68,7 @@ class CheckoutBootstap {
|
|||
jQuery( document.body ).on(
|
||||
'updated_checkout payment_method_selected',
|
||||
() => {
|
||||
this.invalidatePaymentMethods();
|
||||
this.updateUi();
|
||||
}
|
||||
);
|
||||
|
@ -174,6 +175,14 @@ class CheckoutBootstap {
|
|||
);
|
||||
}
|
||||
|
||||
invalidatePaymentMethods() {
|
||||
/**
|
||||
* Custom JS event to notify other modules that the payment button on the checkout page
|
||||
* has become irrelevant or invalid.
|
||||
*/
|
||||
document.body.dispatchEvent( new Event( 'ppcp_invalidate_methods' ) );
|
||||
}
|
||||
|
||||
updateUi() {
|
||||
const currentPaymentMethod = getCurrentPaymentMethod();
|
||||
const isPaypal = currentPaymentMethod === PaymentMethods.PAYPAL;
|
||||
|
@ -232,9 +241,17 @@ class CheckoutBootstap {
|
|||
}
|
||||
}
|
||||
|
||||
setVisible( '#ppc-button-ppcp-googlepay', isGooglePayMethod );
|
||||
/**
|
||||
* Custom JS event that is observed by the relevant payment gateway.
|
||||
*
|
||||
* Dynamic part of the event name is the payment method ID, for example
|
||||
* "ppcp-credit-card-gateway" or "ppcp-googlepay"
|
||||
*/
|
||||
document.body.dispatchEvent(
|
||||
new Event( `ppcp_render_method-${ currentPaymentMethod }` )
|
||||
);
|
||||
|
||||
jQuery( document.body ).trigger( 'ppcp_checkout_rendered' );
|
||||
document.body.dispatchEvent( new Event( 'ppcp_checkout_rendered' ) );
|
||||
}
|
||||
|
||||
shouldShowMessages() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue