mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
fix buttons on checkout
This commit is contained in:
parent
8ff6ba320e
commit
a6eb731590
3 changed files with 26 additions and 626 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -29,32 +29,6 @@ const bootstrap = ()=> {
|
||||||
renderer.render(defaultConfigurator.configuration())
|
renderer.render(defaultConfigurator.configuration())
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Configure checkout buttons
|
|
||||||
jQuery( document.body ).on( 'updated_checkout', () => {
|
|
||||||
if (document.querySelector(PayPalCommerceGateway.button.cancel_wrapper)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderer = new Renderer(
|
|
||||||
PayPalCommerceGateway.button.wrapper
|
|
||||||
);
|
|
||||||
renderer.render(defaultConfigurator.configuration());
|
|
||||||
|
|
||||||
jQuery( document.body ).trigger( 'payment_method_selected' )
|
|
||||||
} );
|
|
||||||
jQuery( document.body ).on( 'payment_method_selected', () => {
|
|
||||||
// TODO: replace this dirty check, possible create a separate context config
|
|
||||||
const currentPaymentMethod = jQuery('input[name="payment_method"]:checked').val();
|
|
||||||
|
|
||||||
if (currentPaymentMethod !== 'ppcp-gateway') {
|
|
||||||
jQuery(PayPalCommerceGateway.button.wrapper).hide();
|
|
||||||
jQuery('#place_order').show();
|
|
||||||
} else {
|
|
||||||
jQuery(PayPalCommerceGateway.button.wrapper).show();
|
|
||||||
jQuery('#place_order').hide();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
// Configure context buttons
|
// Configure context buttons
|
||||||
if (! document.querySelector(PayPalCommerceGateway.button.wrapper)) {
|
if (! document.querySelector(PayPalCommerceGateway.button.wrapper)) {
|
||||||
return;
|
return;
|
||||||
|
@ -87,6 +61,30 @@ const bootstrap = ()=> {
|
||||||
renderer.render(configurator.configuration())
|
renderer.render(configurator.configuration())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (context === 'checkout' ) {
|
||||||
|
configurator = defaultConfigurator;
|
||||||
|
|
||||||
|
if (!document.querySelector(PayPalCommerceGateway.button.cancel_wrapper)) {
|
||||||
|
|
||||||
|
const toggleButtons = () => {
|
||||||
|
const currentPaymentMethod = jQuery('input[name="payment_method"]:checked').val();
|
||||||
|
|
||||||
|
if (currentPaymentMethod !== 'ppcp-gateway') {
|
||||||
|
renderer.hideButtons();
|
||||||
|
jQuery('#place_order').show();
|
||||||
|
} else {
|
||||||
|
renderer.showButtons();
|
||||||
|
jQuery('#place_order').hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jQuery(document.body).on('updated_checkout', () => {
|
||||||
|
renderer.render(defaultConfigurator.configuration());
|
||||||
|
jQuery(document.body).trigger('payment_method_selected')
|
||||||
|
});
|
||||||
|
jQuery(document.body).on('payment_method_selected', toggleButtons );
|
||||||
|
toggleButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (! configurator) {
|
if (! configurator) {
|
||||||
console.error('No context for button found.');
|
console.error('No context for button found.');
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue