How to Disable the "Proceed to Checkout" Button if There Are Errors in the Cart

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

add_action('wp_head', function(){
	?>
	<script>
	jQuery(document).ready(function(){
		jQuery('body.woocommerce-cart').on('click', '.wc-proceed-to-checkout', function(e){
		    if (jQuery('.woocommerce-error').length > 0) {
		        e.preventDefault();
		    }
		});
	});
	</script>
	<?php
});

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

How to Hide or Show the "Proceed to Checkout" Button #

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

add_action('wp_head', function(){
	?>
	<script>
	jQuery(document).ready(function(){
		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');
		    }
		});
	});
	</script>
	<?php
});

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

Powered by BetterDocs