WooCommerce: How to exclude products from discount coupons

coupons

Creating and configuring coupons in WooCommerce is very simple, and they are a fantastic tool to increase your sales and customer loyalty.

However, sometimes you may not want to be able to apply coupons to a product, and that’s what this small and simple guide is for.

Exclude products from a discount coupon

To exclude one or more products from a discount coupon you don’t need codes or plugins, WooCommerce itself includes the tools to do it.

You just have to edit the coupon or coupons where you want to exclude the product or products and, in the “Usage restriction” tab start typing the name of the product or products you want to exclude from the coupon you are modifying or creating.

When you save the changes to the coupon it will no longer be applicable to that product(s).

You can also exclude entire categories from coupons.

Only that in this case you must select the category or categories to exclude from the discount coupon in the exclude categories list.

eclude products and categories from coupons settings

Exclude a product from all discount coupons

Want something more radical? You can automatically exclude a product from all existing and future discount coupons with a simple code like this one:

/* Exclude product from all coupons */
add_filter( 'woocommerce_coupon_is_valid_for_product', 'wphelp_exclude_product_coupons', 9999, 4 );
function wphelp_exclude_product_coupons( $valid, $product, $coupon, $values ) {
if ( 7438 == $product->get_id() ) {
$valid = false;
}
return $valid;
}Code language: PHP (php)

In this code you have to replace the ID of the example product (7438) with the one you want to exclude.

To know the ID of a product just hover over it in the WooCommerce product listing screen.

product id

Add your already customized code to your utilities and tricks plugin so that no coupon can be applied to that product.

As you will see it is not complicated to exclude WooCommerce products from discount coupons, and we have seen several ways to do it.

How useful was this post?

Click on a smiley to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

About The Author

Leave a Comment

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

Scroll to Top