/**
* Check if cart reached minimum amount, if not - display notice.
*/
function dorzki_wc_minimum_cart_check() {
// Minimum cart total.
$minimum_amount = 150;
if( WC()->cart->subtotal < $minimum_amount ) {
wc_print_notice( sprintf( __( 'You need to meet the required minimum of <strong>%s</strong> in order to proceed to checkout.', 'woocommerce' ), wc_price( $minimum_amount ) ), 'error' );
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
}
}
add_action( 'woocommerce_before_cart', 'dorzki_wc_minimum_cart_check' );
Credit: dorzki.co.il
How to use it?
Usually adding functionality to a WordPress site is by creating a plugin.
However you can simply copy the code and paste it in your child theme’s functions.php
file at the end of the file, just before ?>
.
For JavaScript code you will need to add them to your theme’s main JavaScript file.
Having issues with the code?
If the code doesn’t work or you get an error please let us know in the comments section.
We will do our best to fix it as-soon-as-possible and update the code on this page.
Comments