Woo-commerce | Disable proceed to checkout button in cart page if total in cart less than 15 [closed]

We are using woocommerce and we need to disable the checkout button if the total in cart less than 15.

I used this function:

function disable_checkout_button_no_shipping() { 

    $total = WC()->cart->subtotal;
    if( $total < 15 ){
        remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
        echo '<a href="#" class="checkout-button button alt wc-forward">Proceed to checkout</a>';
    }  
}

add_action( 'woocommerce_proceed_to_checkout', 'disable_checkout_button_no_shipping', 1 );

this function created by Patel Jignesh but it doesn’t work!

Our Cart Page total is

1 Answer
1

Try this:

function disable_checkout_button_no_shipping() { 

    $total = WC()->cart->get_cart_subtotal(); // Change made
    if( $total < 15 ){
        remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
        echo '<a href="#" class="checkout-button button alt wc-forward">Proceed to checkout</a>';
    }  
}

add_action( 'woocommerce_proceed_to_checkout', 'disable_checkout_button_no_shipping', 1 );

Leave a Comment