Setting a Minimum Order Amount in Woocommerce

by | Aug 24, 2023 | Business

If you want to set a minimum order amount in Woocommerce, there is a simple fix that can be added to functions.php in your website theme.
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:

  1. Backup your WordPress site: Always take a backup before making any changes. This way, you can easily revert back if something goes wrong.
  2. 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’s functions.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.
  3. 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.
  4. 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.

Why We Like Combining Divi and ACF

I want to show you how we can use ACF and Toolset to insert dynamic content into our text editor. With ACF, we can easily find available fields and insert them into our content. We can also enable raw HTML to display content verbatim. Toolset works similarly, but it...

What Should You Consider Before A Website Re-Design

Let's dive into the essential considerations for undertaking a website redesign. There are both minor and major technical issues, ensuring mobile readiness, optimizing for search engines, and possibly migrating to a more reliable platform, such as WordPress....

Clearing Your Cache In WordPress

Caching is a storage of the presentation of data. Caching is vital to contain how much processing power is needed to run your site. It can also be a pain when a cache holds onto old information. When a user is looking at a database driven web page, there’s a high...

Building A Website For An Electrical Contractor

For an electrical contracting company, we help by creating a new website to replace an existing legacy infrastructure that is bound to hosing and support. WordPress frees up a website and to be hosted on the best platform available. Our designs are clean, responsive,...

How Would We Tackle a Pilates Website Rebuild

We're been asked several times about how we would re-design a pilates or fitness website. Here's a quick rundown of what we recommend. We propose the following features & functions: Move site hosting to WPPro.ca (managed, optimized WordPress hosting). Update the...

Web321 Won the 2023 ICCC-KFC Recipe For Success

We’re excited to share that we won the $30,000 CAD grant through the ICCC-KFC Recipe for Success Program! Thank you to Inner City Capital Connections and KFCCanada for the opportunity to participate in the ICCC program and receive this grant. We look forward to using it to help our business continue to grow!

Why People Like Elementor (but we still don’t)

The TLDR: There is no real comparison between Elementor and Divi; however, it doesn't necessarily mean that Elementor is the best option. We use Divi and we love it. For us, Divi can turn out fantastic results. Why is Elementor considered better? Unlike Divi,...