diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js index 540b085c1..8e88d0a2b 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js @@ -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() { diff --git a/modules/ppcp-button/resources/js/modules/Helper/ButtonDisabler.js b/modules/ppcp-button/resources/js/modules/Helper/ButtonDisabler.js index 9e4bf51ee..ae7f3665c 100644 --- a/modules/ppcp-button/resources/js/modules/Helper/ButtonDisabler.js +++ b/modules/ppcp-button/resources/js/modules/Helper/ButtonDisabler.js @@ -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('> *') diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 4625fab5a..4ba295547 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -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. *