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.

WooCommerce Minimum Order ValueWooCommerce Minimum Order Value
WooCommerce Minimum Order Value

PHP Snippet: Define a Minimum Order Amount and Show Error Messages @ Cart & Checkout

/**
 * @snippet       WooCommerce: Define Minimum Order Amount & Show Errors
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_checkout_process', 'bbloomer_wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'bbloomer_wc_minimum_order_amount' );
  
function bbloomer_wc_minimum_order_amount() {
     
    $minimum = 25; // change this to your minimum order amount
 
    if ( WC()->cart->subtotal < $minimum ) {
 
        if ( is_cart() ) {
 
            wc_print_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' );
 
        } 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' );
 
        }

    }
 
}
Share:

Leave a Reply