0

I want to remove the "Proceed to checkout" buttons in the cart if the cart amount is below 20$.

I found a way to remove the default checkout button with this code:

function disable_checkout_button() {

    // Set this variable to specify a minimum order value
    $minimum = 20;
    $total = WC()->cart->cart_contents_total;
    if( $total < $minimum ){
        remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
    }
}

But the PayPal Express Checkout button is still there. Is there a way to remove that button in the same way?

I didn't found an hook to do it.

EDIT: I read here, that the PayPal buttons are added to the cart page using the woocommerce_proceed_to_checkout hook.

But adding the following line doesn't do anything for me:

remove_action( 'woocommerce_proceed_to_checkout', 'display_paypal_button', 20 );
Cray
  • 5,307
  • 11
  • 70
  • 166
  • Is [setting a minimum order amount](https://woocommerce.com/document/minimum-order-amount/) more what you are after. – Nigel Ren Jul 30 '22 at 11:28
  • I've already added that code. But it shows only the error message. The user can go to the checkout – Cray Jul 30 '22 at 11:33
  • How about https://stackoverflow.com/questions/55038477/set-a-minimum-order-amount-in-woocommerce – Nigel Ren Jul 30 '22 at 11:36
  • My code above is from an answer (https://stackoverflow.com/a/55039131/1788961) of that question. It works but it doesn't hide the PayPal button. – Cray Jul 30 '22 at 11:38

1 Answers1

1
add_filter( 'woocommerce_available_payment_gateways', 'disable_paypal' );
 
function disable_paypal( $available_gateways ) {
$minimum = 20;
if ( WC()->cart->total > $minimum ) {
unset( $available_gateways['ppec_paypal'] );
}
return $available_gateways;
}

Check for available payment gateway set the minimum amount and then disable Paypal.

Dotsquares
  • 755
  • 1
  • 2
  • 10