mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Add filter woocommerce_paypal_payments_product_button_disabled to disable PayPal buttons on single product page.
This commit is contained in:
parent
315ef2c2cd
commit
e94316aecd
3 changed files with 24 additions and 2 deletions
|
@ -96,7 +96,8 @@ class SingleProductBootstap {
|
||||||
|
|
||||||
return this.shouldRender()
|
return this.shouldRender()
|
||||||
&& !this.priceAmountIsZero()
|
&& !this.priceAmountIsZero()
|
||||||
&& ((null === addToCartButton) || !addToCartButton.classList.contains('disabled'));
|
&& ((null === addToCartButton) || !addToCartButton.classList.contains('disabled'))
|
||||||
|
&& this.gateway.button.is_disabled !== true;
|
||||||
}
|
}
|
||||||
|
|
||||||
priceAmount() {
|
priceAmount() {
|
||||||
|
|
|
@ -36,7 +36,10 @@ export const setEnabled = (selectorOrElement, enable, form = null) => {
|
||||||
|
|
||||||
if (form) {
|
if (form) {
|
||||||
// Trigger form submit to show the error message
|
// Trigger form submit to show the error message
|
||||||
jQuery(form).find(':submit').trigger('click');
|
let $form = jQuery(form);
|
||||||
|
if ($form.find('.single_add_to_cart_button').hasClass('disabled')) {
|
||||||
|
$form.find(':submit').trigger('click');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.find('> *')
|
.find('> *')
|
||||||
|
|
|
@ -860,6 +860,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
'wrapper' => '#ppc-button-' . PayPalGateway::ID,
|
'wrapper' => '#ppc-button-' . PayPalGateway::ID,
|
||||||
'mini_cart_wrapper' => '#ppc-button-minicart',
|
'mini_cart_wrapper' => '#ppc-button-minicart',
|
||||||
'cancel_wrapper' => '#ppcp-cancel',
|
'cancel_wrapper' => '#ppcp-cancel',
|
||||||
|
'is_disabled' => $this->is_button_disabled(),
|
||||||
'mini_cart_style' => array(
|
'mini_cart_style' => array(
|
||||||
'layout' => $this->style_for_context( 'layout', 'mini-cart' ),
|
'layout' => $this->style_for_context( 'layout', 'mini-cart' ),
|
||||||
'color' => $this->style_for_context( 'color', 'mini-cart' ),
|
'color' => $this->style_for_context( 'color', 'mini-cart' ),
|
||||||
|
@ -1350,6 +1351,23 @@ class SmartButton implements SmartButtonInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function is_button_disabled(): bool {
|
||||||
|
if ( 'product' !== $this->context() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$product = wc_get_product();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to decide if the button should be disabled for a given product
|
||||||
|
*/
|
||||||
|
return apply_filters(
|
||||||
|
'woocommerce_paypal_payments_product_button_disabled',
|
||||||
|
false,
|
||||||
|
$product
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all payment tokens for the user, via API or cached if already queried.
|
* Retrieves all payment tokens for the user, via API or cached if already queried.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue