function w321_set_minimum_order_amount() { // Set the minimum order amount $minimum = 30; // Get the Cart's total $cart_total = WC()->cart->total; // If the Cart's total is less than the minimum amount, display an error if ($cart_total < $minimum) { 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($cart_total), wc_price($minimum) ), 'error' ); } } add_action('woocommerce_check_cart_items', 'w321_set_minimum_order_amount');
Here’s a step-by-step guide to implement this:
- Backup your WordPress site: Always take a backup before making any changes. This way, you can easily revert back if something goes wrong.
- Add the code: You can add the above PHP code in one of the following places:
- Child Theme’s
functions.php
file: If you are using a child theme, you can add the code to your child theme’sfunctions.php
file. This ensures that your changes aren’t overwritten when the parent theme updates. - Custom Plugin: If you prefer to keep your customizations separate from your theme, you can create a simple custom plugin and add the code there.
- Child Theme’s
- Test: After adding the code, try adding items to your cart and checking out with less than $30 to see if the error message appears.
- Adjust the minimum value: If in the future you want to change the minimum order amount, just adjust the
$minimum
value in the code.
Remember that while this method sets a minimum transaction amount, there may be additional configurations or plugins on your WooCommerce site that could conflict with this. Always test thoroughly after making changes.