It is not uncommon for store owners to have the need to set a minimum order amount before any order can be completed. This can be due to handling, processing and/or shipping costs making the sale unprofitable. Today we’re going to add a small snippet to our theme which will allow store owners to set a minimum order amount for all their orders.

Install and activate a child theme

As always the first step on our process here is to create and install a child theme. If you are using one of our themes you can easily grab its child theme from our downloads section. If not, you can read our beginner’s guide on child themes to create your own. This step is essential in order to preserve our changes throughout theme updates.

All code below will be placed in our child theme’s functions.php file. If the file is empty the code will go just below the opening <?php tag, otherwise, if it has contents, the code should be placed at the end of the file, before the closing ?> PHP tag if it exists.

Add the code to set the minimum order amount

add_action( 'woocommerce_checkout_process', 'cssigniter_set_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'cssigniter_set_minimum_order_amount' ); function cssigniter_set_minimum_order_amount() { // Change the number below to modify the minimum amount. $minimum = 50; if ( WC()->cart->total < $minimum ) { if ( is_cart() ) { wc_print_notice( sprintf( /* translators: %1$s: current order total %2$s: minimum order total */ __( 'Your current order total is %1$s — you must have an order with a minimum of %2$s to place your order ', 'your-text-domain' ), wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } else { wc_add_notice( sprintf( /* translators: %1$s: current order total %2$s: minimum order total */ __( 'Your current order total is %1$s — you must have an order with a minimum of %2$s to place your order ', 'your-text-domain' ), wc_price( WC()->cart->total ), wc_price( $minimum ) ), 'error' ); } }
}

In line 6 above you can customize the minimum order amount. With the code in place the user will get a notice on the cart page regarding the minimum order amount if their order does not exceed it. Furthermore if they proceed to the checkout and try to place the order they will be presented with the same error notice regarding the minimum order amount.

Wrapping up

This quick guide has helped us set a minimum order amount, orders below that amount will get a notice informing the customers that they need to increase their cart total otherwise they won’t be able to proceed with order placement. Let us know if this guide has helped you on your WooCommerce based store, and interesting ideas you might have for future guides in the comments below.

The post Set a minimum order amount for WooCommerce orders appeared first on CSSIgniter.