How To Get WooCommerce To Add Discounts Programmatically

How To Get WooCommerce To Add Discounts Programmatically

Coupons should be easy to use. For a lot of users, copying or transcribing long coupon codes can be a hassle. If you want as many people as possible to take advantage of the deals you set up, you’ll want to consider configuring WooCommerce to add discounts programmatically.

If you’re using Advanced Coupons, that process is easier than you might think. The plugin offers more than one way to automate or semi-automate coupon application. That way, you can ensure no customer is left out.

In this tutorial, we’ll talk about why it makes sense to set up WooCommerce to add discounts programmatically. Then we’ll show you two ways to do it. Let’s get to work!

Why You Should Simplify the Coupon Application Process

Discounts and promotions are perhaps the most powerful tools at your disposal to increase sales, and coupons enable you to implement both. The only downside to using coupons is that you leave a lot of work in your customer’s hands.

If you send a coupon code via email and a user doesn’t see it, they can lose out on potential savings. Even if you add a big notice on your homepage, a lot of visitors might overlook it.

In our experience, customers that find out they could’ve gotten a discount on their purchases but didn’t aren’t a particularly happy lot. They might be more likely to complain and less likely to buy from you again in the future.

Ideally, you’d like to avoid both scenarios. A smart way to do so is to configure WooCommerce to add discounts programmatically. In other words, if a purchase fulfills a set of specific conditions, it gets a discount without users needing to do any extra work.

With that approach, you can minimize the number of users that miss out on promotions. If everything goes smoothly, you’ll get more sales and your customers should be happier – it’s a win-win.

How to Get WooCommerce to Add Discounts Programmatically (2 Ways)

The easiest way to automate discounts in WooCommerce is by using a plugin such as Advanced Coupons:

The Advanced Coupons plugin.

With Advanced Coupons, you can set up anything from discounted shipping to Buy One Get One (BOGO) deals, all through the magic of coupons. Plus, you can get WooCommerce to add discounts programmatically in more than one way.

1. Use the auto-apply feature

Advanced Coupon’s auto-apply feature does exactly what its name promises. You can enable it independently for each coupon you offer. If a customer’s purchase meets the criteria for a coupon with auto-apply enabled, they won’t need to enter the code manually.

Turning on that feature is simple. All you have to do is open the coupon editor and look for the Auto Apply Coupon section on the right side of the screen:

Getting WooCommerce to add discounts programmatically.
(click to zoom)

Before you enable auto-apply for any coupon, it’s important you properly configure its restrictions and/or conditions. For example, you might want to limit that coupon’s usage to once per customer, which you can do under Coupon data > Usage limits:

Configuring usage limits for your coupon.
(click to zoom)

To set cart conditions, you can scroll down to the Cart Conditions > Rules section. Here, you can use a simple conditions system to ensure customers meet specific criteria before the plugin auto-applies that coupon:

Some examples or cart conditions for a coupon.
(click to zoom)

You can enable auto-apply for as many or a few of your coupons as you want. We recommend you use the feature only for those discounts you don’t want any customers to miss, though.

2. Enable one-click coupon application

Advanced Coupons also lets you set up a one-click-apply option for your customers. This approach isn’t precisely automatic, but it’s as close as you can get without enabling auto-apply for your WooCommerce discounts.

One-click coupon application is perfect if you don’t feel comfortable turning on auto-apply for your discounts. It makes coupons easy to apply without taking all the work off your customer’s hands, which can be a good thing.

Another benefit of this approach is you can customize your one-click-apply notifications. That includes everything from the apply button text to error messages and more:

Enabling one-click coupon application.
(click to zoom)

You can find that option as well as its accompanying settings under Coupon data > One Click Apply Notification. Keep in mind that this is also a coupon-specific option. That means if you want to offer one-click coupon application for all your discounts, you’ll have to enable the setting for each of them.


Automating coupon application makes it easier for users to take advantage of the deals you set up for them. With programmatically-applied coupons, you can ensure no user loses out on a deal because they didn’t check their email or see the notices you set up.

With Advanced Coupons, you can get WooCommerce to add discounts programmatically in two ways:

  1. Use the auto-apply feature.
  2. Enable one-click coupon application.

Do you have any questions about how to get WooCommerce to add discounts programmatically? Let’s talk about them in the comments section below!


Leave a Reply

Your email address will not be published. Required fields are marked *