Skip to content
ArAgile.
← All insights

Set minimum purchase value for Woocommerce orders

If you need to restrict a minimum amount for checkout, use the following code:

add_action( 'woocommerce_check_cart_items', 'aragile_woocommerce_check_cart_items' );

function aragile_woocommerce_check_cart_items() {
    if ( is_cart() || is_checkout() ) {
        if ( WC()->cart->get_cart_contents_count() > 0 ) {
            $minimum_cart_total = 20;

            if( WC()->cart->subtotal < $minimum_cart_total  ) {
                wc_add_notice( sprintf( '<strong>A minimum of %s USD is required before checking out.</strong>' . " Current cart's total is %s AMD", $minimum_cart_total, WC()->cart->subtotal ), 'error' );
            }
        }
    }
}

It will show an error when the total price of the cart is less than 20 USD.

A good place to start

Tell us what you want
to build. We’ll work it out.

Let’s talk about your project