Conditionally disable PayPal Smart Button
-
Hi,
I’m working on a project where I need to conditionally disable the PayPal smart button (on product pages, cart pages, express checkout, etc.).
In a previous project we achieved this without any issues using your plugin. The main difference is that the earlier project was based on the classic cart and checkout, while the new one is using the WooCommerce Cart and Checkout Blocks.
I have tried the same approach as before, but it does not seem to work with the blocks. I’ve scanned through your code multiple times to find a hook or method I can use, but so far without luck.
What I have tried:
- Deregistering scripts from
PaymentPlugins\WooCommerce\PPCP\PaymentButtonController. - Scripts being deregistered:
woocommerce_before_add_to_cart_formwoocommerce_update_order_review_fragmentswoocommerce_checkout_before_customer_detailswoocommerce_review_order_after_submitwoocommerce_widget_shopping_cart_buttonswoocommerce_proceed_to_checkoutwoocommerce_after_add_to_cart_button- I have also tried unsetting the gateway, like below. This remove the Smart button from the Payment Options, but not the Express Checkout
/**
* Disable PayPal blocks functionality
*/
add_filter( 'woocommerce_available_payment_gateways', function ($gateways) {
if(age_verification_is_required()){
unset( $gateways['ppcp'] );
}
return $gateways;
} );What I found when looking into the blocks setup:
- It seems like the smart button is being handled by
/packages/blocks/build/paypal.js. - However, I haven’t been able to find where this script is enqueued or how it’s registered, so I’m stuck at that point.
Is there a recommended way to disable the smart button when using the cart and checkout blocks?
Any help or pointers would be greatly appreciated!
- Deregistering scripts from
The topic ‘Conditionally disable PayPal Smart Button’ is closed to new replies.