65
Today we take a look at the WooCommerce Minimum Order Amount. This snippet displays an error notification on the Cart Page and an error message @ Checkout Process if the order is below a set threshold.
PHP Snippet: Define a Minimum Order Amount and Show Error Messages @ Cart & Checkout
/**
* @snippet WooCommerce: Define Minimum Order Amount & Show Errors
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 3.8
* @donate $9 https://tutoraspire.com
*/
add_action( 'woocommerce_checkout_process', 'tutoraspire_wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'tutoraspire_wc_minimum_order_amount' );
function tutoraspire_wc_minimum_order_amount() {
$minimum = 25; // change this to your minimum order amount
if ( WC()->cart->subtotal cart->subtotal ) ), 'error' );
} else {
wc_add_notice(
sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' );
}
}
}