As a WooCommerce store owner and a good business owner, I’m sure you are constantly trying to increase the average order value.

One tried and tested method is to offer coupons that apply to orders over a set amount. For instance 20% off if you spend over €100.

This type of coupon is a great method to encourage your customers to spend that little bit more and in doing so, to get additional value by availing of the discount.

It’s a win-win situation.

But how do you do this without adding more plugins?

In this short blog, we will teach you how to apply a coupon code for a minimum cart value AND have the coupon apply automatically on checkout.

According to Wikibuy, providing coupon codes persuades 37% of consumers to buy more.

How does minimum cart value work?

Imagine you’ve set up a minimum cart value of €60 to apply a discount coupon that gives 50% off.

Then, only those customers who have purchased more than €60 will be able to use a discount coupon.

To make it more convenient for customers, the coupons will be automatically applied if the cart value is more than €60.

You can display a coupon message on the cart page to persuade your customers to purchase more – if they do not meet the threshold.

How does a coupon for minimum cart value benefit you?
  • Helps in upselling
  • Helps in cross-selling
  • You will be able to attract more customers and generate more revenue
  • You will be able to cover the shipping costs if you’re selling cheaper products.

To complete this function we will need to add a code snippet.

This code snippet will show your customers a notice on the cart and the checkout page about the discount coupon/offer they get if they purchase for a specified minimum amount.

Here’s what you need to do to create an automate coupon in WooCommerce

First, you need to create a coupon called “COUPON” (this can be changed as long as the code is changed to reflect the name) on WooCommerce > Coupons without a minimum amount and adjust the minimum amount variable to a minimum amount according to your choice in the code snippet.

Then, edit the notices on the code below to your desired notice.

Now let’s take a look at the step-by-process.

We are going to set up a minimum cart value of 60 in order to get a discount coupon.

  1. Log into your WordPress dashboardLog in
    Next, you need to add this snippet code to the child theme’s functions.php. Do not add the custom code directly to your parent theme’s functions.php file. PLEASE NOTE the notice wording and amounts in the code below.

    /**
    * Apply a coupon for minimum cart total
    */
    
    add_action( 'woocommerce_before_cart' , 'add_coupon_notice' );
    add_action( 'woocommerce_before_checkout_form' , 'add_coupon_notice' );
    
    function add_coupon_notice() {
    
            $cart_total = WC()->cart->get_subtotal();
            $minimum_amount = 50;
            $currency_code = get_woocommerce_currency();
            wc_clear_notices();
    
           if ( $cart_total < $minimum_amount ) {
                  WC()->cart->remove_coupon( 'COUPON' );
                  wc_print_notice( "Get 50% off if you spend more than $minimum_amount $currency_code!", 'notice' );
            } else {
                  WC()->cart->apply_coupon( 'COUPON' );
                  wc_print_notice( 'You just got 50% off your order!', 'notice' );
            }
              wc_clear_notices();
    }
  2.  On the left panel of the dashboard, go to Appearance>Theme Editor> functions.php. Or you can update the child themes functions.php file via ftp, please only amend the child theme’s functions.php file. If you are not running a child theme, you will first need to create one and switch to the child theme.
    Then add the snippet code. Set the minimum cart value at 60 to get offer coupons. Save the file.

Set minimum amount

Snippet code
In the snippet code, we set the minimum amount at 60.

Now you can show the coupon on the cart page as shown below. Here the total cart value of the customer is €50.

So the customer will be reminded to increase the cart value to more than €60 to get a 50% off.
Cart value

Let’s see what happens if the minimum cart value is set to €40 as shown below.

cart value 40
The minimum cart value is 40 here.

Now if the customer makes a purchase for €50, then the coupon will automatically be applied.

Above cart value
The discount has already been applied since the minimum cart value is €40

That’s it. Now you have learnt to apply a coupon for a minimum cart total.

Did you find this article helpful? Then you will also find our services handy. Contact us now