mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add shouldRender method for the context bootstrappers
This commit is contained in:
parent
9f1a633ad9
commit
5990d9766b
4 changed files with 34 additions and 27 deletions
|
@ -6,18 +6,11 @@ class CheckoutBootstap {
|
|||
}
|
||||
|
||||
init() {
|
||||
const buttonWrapper = PayPalCommerceGateway.button.wrapper;
|
||||
const cancelWrapper = PayPalCommerceGateway.button.cancel_wrapper;
|
||||
|
||||
if (!document.querySelector(buttonWrapper)) {
|
||||
if (!this.shouldRender()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.querySelector(cancelWrapper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new Renderer(buttonWrapper);
|
||||
const renderer = new Renderer(PayPalCommerceGateway.button.wrapper);
|
||||
|
||||
jQuery(document.body).on('updated_checkout', () => {
|
||||
renderer.render(this.configurator.configuration());
|
||||
|
@ -31,17 +24,25 @@ class CheckoutBootstap {
|
|||
'input[name="payment_method"]:checked').val();
|
||||
|
||||
if (currentPaymentMethod !== 'ppcp-gateway') {
|
||||
jQuery(buttonWrapper).hide();
|
||||
jQuery(PayPalCommerceGateway.button.wrapper).hide();
|
||||
jQuery('#place_order').show();
|
||||
}
|
||||
else {
|
||||
jQuery(buttonWrapper).show();
|
||||
jQuery(PayPalCommerceGateway.button.wrapper).show();
|
||||
jQuery('#place_order').hide();
|
||||
}
|
||||
});
|
||||
|
||||
renderer.render(this.configurator.configuration());
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
if (document.querySelector(PayPalCommerceGateway.button.cancel_wrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return document.querySelector(PayPalCommerceGateway.button.wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckoutBootstap;
|
Loading…
Add table
Add a link
Reference in a new issue