How to disable the "Proceed to Checkout" button if there are errors in the cart

f you are using Dynamic Rules such as "Minimum Order" and would like to prevent the user from clicking "Proceed to Checkout" when there are errors in the cart, you can add the following JavaScript snippet to your website. It will make the button non-functional when clicked.

jQuery('body.woocommerce-cart').on('click', '.wc-proceed-to-checkout', function(event){
    if (jQuery('.woocommerce-error').length > 0) {
        event.preventDefault();
    }
});

Depending on theme, you may have to change ".woocommerce-error" to ".woocommerce-info"

How to hide/show the proceed to checkout button

If you want to completely hide/show the button based on cart errors, you can add the following snippet to your website:

jQuery( document.body ).on( 'updated_cart_totals', function(){
    if (jQuery('.woocommerce-error').length > 0) {
        jQuery('.wc-proceed-to-checkout').css('display','none');
    } else {
       jQuery('.wc-proceed-to-checkout').css('display','block');
    }
});

Warning: it may not work correctly with all websites/themes/setups, so make sure to test it under multiple circumstances to make sure there are no issues or conflicts..

Did you find this article useful?