WooCommerce is one of the most popular e-commerce platforms in the world. It is used by thousands of online stores and offers a plethora of features to help store owners create and manage their stores.
One of the options that online store owners often need to set up is a minimum order amount. This is usually necessary in stores that send the physical product to the customer’s address, preventing purchases for a product of small value whose shipping does not compensate.
In the solution that we present here, it is not necessary to install any plugin, but we recommend using the Code Snippets plugin so that it is possible to insert the code in a simpler and more organized way.
You can also insert the code directly into your child theme’s functions.php file.
<?php
/*
* WordPress Snippet: WooCommerce minimum order amount
* Author: Fellipe Soares
* Author URI: https://www.amicatek.com/en/
* Data Criação: Dec 26 2022
* Data Alteração: Dec 26 2022
*/
function amk_wc_min_order_amount( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
if ( WC()->cart->get_cart_contents_total() < 30 ) {
wc_print_notice(
sprintf( 'The minimum amount to finalize the order is $30.00. Your current order is $ %s',
WC()->cart->get_cart_contents_total() ), 'error'
);
}
}
add_action( 'woocommerce_check_cart_items', 'amk_wc_min_order_amount' );
Explaining the code: In this snippet we define a minimum value of $30.00 per order as a rule. The script will evaluate if the total cart value is less than 30.00.
If so, it will show a message on the screen informing that the minimum amount to complete the order is $30.00, and also informing the total amount of the order.
If you have any problems applying this script, please use the comments section to let us know.
Oh, if it works, let us know too. We’ll be happy to have helped.


