Want to reward shoppers without asking them to enter a code at checkout? With a small snippet, you can have WooCommerce automatically apply a coupon when an order meets your requirements. It’s a simple way to make discounts easier to claim and create a smoother shopping experience.
In this guide, you’ll learn how to set up a WooCommerce automatically apply coupon rule for eligible orders. Add the snippet, adjust it to match your coupon and conditions, and let WooCommerce handle the discount automatically.
Why Automatically Apply Coupons in WooCommerce?
Every extra step at checkout gives shoppers another chance to hesitate. When a customer has already qualified for a promotion, removing the need to find and enter a code can make the offer feel more seamless—and help them understand the final price before placing an order.
When automatic coupons make eligible orders easier to complete
A WooCommerce automatically apply coupon rule is especially useful when eligibility is clear, such as spending over a set amount, buying a particular product, or shopping during a promotion. Instead of asking customers to remember a code from an email or banner, the store can apply the discount when the order meets the conditions.
This can make a promotion easier to use, but the rule should be predictable. For example, if a coupon is intended for orders over $75, make sure shoppers can see the threshold and the discount once they qualify. Clear expectations help avoid confusion if a coupon is removed because the cart no longer meets its requirements.
Automatic application can work well for promotions such as:
- A discount triggered by a minimum cart total.
- A deal tied to a specific product or category.
- A time-limited offer for a sale or seasonal campaign.
Before adding the snippet, it’s worth checking how the coupon is configured in WooCommerce itself. These settings affect whether the automatic rule behaves as intended and can prevent surprises when customers update their carts.
What to check before adding a coupon snippet
Start by confirming that the coupon exists and that its restrictions match the offer you want to automate. WooCommerce’s coupon management documentation covers settings such as usage limits, expiry dates, and product restrictions.
Review the details that could change eligibility, including the minimum spend, included or excluded products, customer usage limits, and whether the coupon can be combined with other discounts. Then test a qualifying cart and a non-qualifying one. Also check what happens when a shopper removes an item or drops below the spending threshold.
Finally, add custom code using a method that’s easier to maintain, such as a snippets plugin or a child theme, rather than editing a parent theme directly. Test the result on a staging site if possible, and check that caching or other coupon plugins don’t interfere with cart updates. With those basics confirmed, you’ll have a clearer path to setting up a reliable automatic discount.
Add a Snippet to Automatically Apply a Coupon in WooCommerce
Once the offer and its rules are clear, the next step is connecting them to your store. A small snippet can check the cart as it updates, apply the discount when the order qualifies, and remove it if the cart no longer meets the condition.
Choosing where the code lives and defining eligibility carefully will make the behavior easier to maintain. Here’s a simple example you can adapt.
Before adding any code, decide how you’ll manage it and test it without affecting live orders. The safest option is one that won’t disappear during a theme update and can be disabled quickly if needed.
Where to add the code safely
Add the snippet with a reputable code snippets plugin, or place it in your child theme’s functions.php file. Avoid editing a parent theme directly: an update can overwrite your changes.
Test on a staging site when possible. If you add code to a live store, keep a recent backup and check for syntax errors before saving. The snippet below uses WooCommerce’s cart functions, so your site should have WooCommerce active.
The example applies coupon save10 when the cart subtotal reaches $75. It also removes that coupon if the subtotal falls below the threshold.
Use the snippet to apply a coupon only to eligible orders
addaction( 'woocommercebeforecalculatetotals', 'mysiteautoapplycoupon' );
function mysiteautoapplycoupon() {
if ( isadmin() && ! defined( 'DOINGAJAX' ) ) {
return;
}
if ( ! WC()->cart ) {
return;
}
static $running = false;
if ( $running ) {
return;
}
$running = true;
$couponcode = 'save10';
$minimumspend = 75;
$eligible = WC()->cart->getsubtotal() >= $minimumspend;
if ( $eligible && ! WC()->cart->hasdiscount( $couponcode ) ) {
WC()->cart->applycoupon( $couponcode );
} elseif ( ! $eligible && WC()->cart->hasdiscount( $couponcode ) ) {
WC()->cart->removecoupon( $couponcode );
}
$running = false;
}The subtotal check is made before shipping, so set the coupon’s own minimum-spend rule to match. WooCommerce still validates the coupon’s other restrictions, such as expiry, usage limits, and product eligibility.
To make the rule fit your promotion, change the coupon code and threshold—and consider whether eligibility should depend on cart value or specific products. Small edits can turn this example into a targeted store rule without changing how the cart is checked.
Customize the coupon code and eligibility conditions
Before enabling the rule, make sure the coupon code in the snippet matches the one in WooCommerce exactly. Then adjust the condition to reflect what shoppers need to do to qualify.
For a product-based offer, you could check cart contents instead of the subtotal. Whatever condition you choose, test both outcomes: a qualifying cart should receive the discount, and removing an item or lowering the total should remove it. This helps confirm that your WooCommerce automatically apply coupon rule behaves as expected throughout checkout.
Test and Troubleshoot Automatic Coupons in WooCommerce
A discount that works in one cart can behave differently after a shopper changes quantities or moves to checkout. A few deliberate tests will show whether the rule applies at the right moment—and whether it cleans up properly when the order no longer qualifies.
Check coupon behavior with eligible and ineligible carts
Begin with a clean cart and test just below, exactly at, and just above the $75 threshold. This confirms the boundary behavior of the snippet’s subtotal check and helps catch differences between the amount shoppers expect to count and WooCommerce’s cart subtotal.
Then check the full journey, not just the first cart view. Update quantities, remove an item, refresh the page, and proceed to checkout. The coupon should appear when the cart qualifies and disappear if a change takes it below the threshold. Also confirm the displayed discount matches the coupon’s settings.
Keep a short test checklist so you can repeat the same checks after changing the snippet or updating a related plugin:
- Eligible cart: the coupon is applied once and the discount is visible.
- Ineligible cart: the coupon is absent or removed.
- Restricted cart: product, expiry, and usage rules still behave as configured.
- Checkout: totals remain consistent after shipping and taxes are calculated.
Fix common conflicts and remove coupons when eligibility changes
If the discount does not appear, first verify that the coupon code in the snippet matches the code in WooCommerce, and check that the coupon is published, unexpired, and valid for the cart. Remember that the example measures subtotal before shipping; a customer’s displayed total may therefore differ from the value used to qualify.
When the cart qualifies but the coupon still fails, temporarily test with other discount, checkout, or cart plugins disabled on a staging site. These tools may change cart calculations or coupon behavior. Also test after a cart update: AJAX-powered mini carts can show stale totals until refreshed, even when the cart itself has recalculated.
If a coupon remains after eligibility changes, confirm that the removal branch is still present and that the condition reflects the promotion you intend. Check for another snippet applying the same coupon or a plugin that automatically re-adds it. WooCommerce’s coupon management documentation can help you review restrictions that may prevent application. Once you identify the cause, retest both qualifying and non-qualifying carts before relying on the WooCommerce automatically apply coupon rule for live orders.
Make Automatic Coupons Work Smoothly for Every Eligible Order
Automatically applying coupons can make promotions easier to claim and checkout more straightforward for your customers. The snippet gives you a flexible starting point: define who qualifies, apply the discount when they do, and remove it if their cart no longer meets the rules.
Before relying on it, make sure the coupon settings and snippet conditions match, then test both qualifying and ineligible carts—including changes made during checkout. A little testing helps catch conflicts and keeps discounts predictable.
With clear offer terms and a well-tested WooCommerce automatically apply coupon rule, you can reward eligible shoppers without asking them to remember a code. Adjust the example to suit your promotion, and give customers a smoother path from cart to checkout.