Add filter woocommerce_paypal_payments_product_button_disabled to disable PayPal buttons on single product page.

This commit is contained in:
Pedro Silva 2023-07-03 08:25:35 +01:00
parent 315ef2c2cd
commit e94316aecd
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
3 changed files with 24 additions and 2 deletions

View file

@ -96,7 +96,8 @@ class SingleProductBootstap {
return this.shouldRender()
&& !this.priceAmountIsZero()
&& ((null === addToCartButton) || !addToCartButton.classList.contains('disabled'));
&& ((null === addToCartButton) || !addToCartButton.classList.contains('disabled'))
&& this.gateway.button.is_disabled !== true;
}
priceAmount() {

View file

@ -36,7 +36,10 @@ export const setEnabled = (selectorOrElement, enable, form = null) => {
if (form) {
// 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('> *')

View file

@ -860,6 +860,7 @@ class SmartButton implements SmartButtonInterface {
'wrapper' => '#ppc-button-' . PayPalGateway::ID,
'mini_cart_wrapper' => '#ppc-button-minicart',
'cancel_wrapper' => '#ppcp-cancel',
'is_disabled' => $this->is_button_disabled(),
'mini_cart_style' => array(
'layout' => $this->style_for_context( 'layout', '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.
*