WooCommerce offers several ways of setting the parameters  for WooCommerce purchase limit. Although the steps are different, the outcome is often identical. However, I consider the following steps to be very effective. I  will use the woocommerce_check_cart_items action provided by WooCommerce to run the functions and execute the code. Â
Setting a Minimum Weight Requirement For WooCommerce Purchase Limit
Many stores often do not allow their customers to checkout until the weight of the purchase does not exceed a pre-set limit. Minimum weight requirements significantly reduce delivery costs and the process becomes more streamlined. Bear in mind that all weight calculations are carried out in weight units set under WooCommerce – > Settings – > Products.
Place the following code in the functions.php, located in the theme folder.
add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' ); function cldws_set_weight_requirements() { // Only run in the Cart or Checkout pages if( is_cart() || is_checkout() ) { global $woocommerce; // Set the minimum weight before checking out $minimum_weight = 30; // Get the Cart's content total weight $cart_contents_weight = WC()->cart->cart_contents_weight; // Compare values and add an error is Cart's total weight if( $cart_contents_weight < $minimum_weight ) { // Display our error message wc_add_notice( sprintf('<strong>A Minimum Weight of %s%s is required before checking out.</strong>' . '<br />Current cart weight: %s%s', $minimum_weight, get_option( 'woocommerce_weight_unit' ), $cart_contents_weight, get_option( 'woocommerce_weight_unit' ), get_permalink( wc_get_page_id( 'shop' ) ) ), 'error' ); } } }
Setting a Minimum Dollar Amount per Order
A minimum dollar amount is another important restriction on the store. Minimum dollar amounts are often used to keep all transactions at a common base value per transaction. To set this limit, Â use the following code
add_action( 'woocommerce_check_cart_items', 'cldws_set_min_total'); function cldws_set_min_total() { // Only run in the Cart or Checkout pages if( is_cart() || is_checkout() ) { global $woocommerce; // Set minimum cart total $minimum_cart_total = 100; // A Minimum of 100 AUD is required before checking out. $total = WC()->cart->subtotal; // Compare values and add an error is Cart's total if( $total <= $minimum_cart_total ) { // Display our error message wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>' .'<br />Current cart\'s total: %s %s', $minimum_cart_total, get_option( 'woocommerce_currency'), $total, get_option( 'woocommerce_currency') ), 'error' ); } } }
Conclusion
WooCommerce permits you to utilize actions and filters to change the ordinary checkout process. I hope that you will implement these two limits to your WooCommerce store. If you need clarification or wish to contribute to the discussion, please leave a comment below.
Owais Alam
is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]