Require a minimum order value in WooCommerce

by Dan
Last updated: September 26th, 2020

This is a useful snippet I picked up when building The Barn Little London‘s online store, due to the nature of their business needing to source and order local products ahead of time, they required customers to have a minimum spend before they were able to place their Order.

I can’t remember where I picked this snippet up from, but I thought I’d share it as it’s a pretty handy one to reach for when building WooCommerce stores.

/** * Set a minimum order amount for checkout */ add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); function wc_minimum_order_amount() { // Set this variable to specify a minimum order value $minimum = 25; if ( WC()->cart->total < $minimum ) { if( is_cart() ) { wc_print_notice( sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' , wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } else { wc_add_notice( sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' , wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } } }

we think you'll probably like these too