• 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_form
      • woocommerce_update_order_review_fragments
      • woocommerce_checkout_before_customer_details
      • woocommerce_review_order_after_submit
      • woocommerce_widget_shopping_cart_buttons
      • woocommerce_proceed_to_checkout
      • woocommerce_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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Clayton R

    (@mrclayton)

    Hi @joped

    Thank you for contacting Payment Plugins. The blocks by WooCommerce are much more opinionated than the classic shortcodes and therefore not as easy to customize or modify. It would be my recommendation to use the shortcode if possible for a project that requires customization.

    That being said, you should be able to conditionally disable the smartbuttons by using the WooCommerce action woocommerce_blocks_payment_method_type_registration:

    add_action('woocommerce_blocks_payment_method_type_registration', function($registry){
    if(your custom condition){
    $registry->unregister('ppcp');
    }
    }, 100);

    Kind Regards

    Hi @mrclayton,
    Thank you for the response and the code snippet. Unfurtunatly for this project it will not be possible to use the shortcode pages. Otherwise that would also have been my go to.

    I will definitly try this tomorrow.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Conditionally disable PayPal Smart Button’ is closed to new replies.