Conditionally disable PayPal Smart Buttons in Mini Cart?
-
Hello,
I was wondering if it was possible to create a function that checks on some conditions and disables the PayPal Smart Buttons in the mini cart aswell.
What I need is a function that prevents the customer to check out using the PayPal Smart Buttons if there is a product from a certain product category in their cart but they haven’t applied a coupon code (coupon is mandatory for some products).
As for now I have the following function which seems to work for the cart page but not the mini cart:
add_filter( 'woocommerce_available_payment_gateways', 'my_disable_paypal' ); function my_disable_paypal( $available_gateways ) { $product_categories = array( 'my-category' ); // category ID or slug of targeted category if( empty(WC()->cart->get_applied_coupons()) ) { // check if any coupons were applied $coupon_applied = false; } else { $coupon_applied = true; } foreach ( WC()->cart->get_cart() as $cart_item ){ // check the cart for products with given product category if no coupons were applied if( has_term( $product_categories, 'product_cat', $cart_item['product_id'] ) && ! $coupon_applied ) { unset( $available_gateways['ppcp-gateway'] ); // found one, disable PayPal payment gateway break; // stop the loop } } return $available_gateways; }
I have found a similar question here but I did not find quite a solution for the mini cart.
So my question is if and how it’s possible to remove PayPal Smart buttons especially from the mini cart.
Would you be so kind and have a look? Could you maybe point me in the right direction?
Thank you in advance!
- The topic ‘Conditionally disable PayPal Smart Buttons in Mini Cart?’ is closed to new replies.