Close Menu
Trendswave MediaTrendswave Media
  • Home
  • About Us
    • Contact Us
  • Services
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • Shop

Subscribe to Updates

Get the latest creative news from Trendswave about Marketing, SEO & Web Design.

Please enable JavaScript in your browser to complete this form.
Loading
What's Hot

In and Out of Model Responses Explained — Whiteboard Friday

March 10, 2026

Balancing Credit Building with Credit Caution

March 10, 2026

How Will AI Impact the Bottom of the Web Design Market? — Speckyboy

March 9, 2026
Facebook X (Twitter) Instagram
Trendswave MediaTrendswave Media
  • Home
  • About Us
    • Contact Us
  • Services
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • Shop
Trendswave MediaTrendswave Media
Home»Web Design»WooCommerce tip: How to manage discounts based on taxonomies
Web Design

WooCommerce tip: How to manage discounts based on taxonomies

adminBy adminApril 9, 2025No Comments4 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp VKontakte Email
WooCommerce tip: How to manage discounts based on taxonomies
Share
Facebook Twitter LinkedIn Pinterest Email


By default, WooCommerce allows us to exclude products that belong to specific categories from discount offers or to apply discounts only to products that belong to particular categories.

The default WooCommerce discount rules for product categoriesThe default WooCommerce discount rules for product categoriesThe default WooCommerce discount rules for product categories

However, it doesn’t provide a straightforward mechanism for defining discount rules for other product taxonomies (e.g. brands and tags).

WooCommerce tag and brand taxonomiesWooCommerce tag and brand taxonomiesWooCommerce tag and brand taxonomies

Of course, we can use a plugin to implement that feature, but it isn’t that difficult to implement ourselves!

All we have to do is take advantage of the woocommerce_coupon_is_valid_for_product filter. If you want to dig deeper into it, you’ll find it inside the class-wc-coupon.php file of the WooCommerce plugin files.

Let’s get a better understanding through some examples!

1. Set a discount only for products (simple or variable) without the Stock Offers tag.

To enable this rule, add the following code in the functions.php file of your theme:

1

2
function wc_custom_coupon_rules( $valid, $product, $coupon, $values ) {
3
    $product_id = $product->get_ID();
4
	if ( 'variation' === $product->get_type() ) :
5
		$product_id = $product->get_parent_id();
6
	endif;
7
	if ( has_term( 'stock-offers', 'product_tag', $product_id ) ) :
8
		$valid = false;
9
	endif;
10
	return $valid;
11
}
12
add_filter( 'woocommerce_coupon_is_valid_for_product', 'wc_custom_coupon_rules', 10, 4 );

With this rule in place, assuming we have available a welcome10 coupon for a 10% discount, a customer with these selections will enjoy a 2.50€ discount.

An example of a discount ruleAn example of a discount ruleAn example of a discount rule

2. Set a discount only for products (simple or variable) with the Stock Offers tag.

To enable this rule, add the following code in the functions.php file of your theme:

1

2
function wc_custom_coupon_rules( $valid, $product, $coupon, $values ) {
3
    $product_id = $product->get_ID();
4
	if ( 'variation' === $product->get_type() ) :
5
		$product_id = $product->get_parent_id();
6
	endif;
7
	if ( ! has_term( 'stock-offers', 'product_tag', $product_id ) ) :
8
		$valid = false;
9
	endif;
10
	return $valid;
11
}
12
add_filter( 'woocommerce_coupon_is_valid_for_product', 'wc_custom_coupon_rules', 10, 4 );

With this rule in place, assuming we have available a welcome10 coupon for a 10% discount, a customer with these selections will enjoy a 3.60€ discount.

An example of a discount ruleAn example of a discount ruleAn example of a discount rule

3. Set a discount only for products (simple or variable) without the Stock Offers tag or the Nike brand.

To enable this rule, add the following code in the functions.php file of your theme:

1

2
function wc_custom_coupon_rules( $valid, $product, $coupon, $values ) {
3
    $product_id = $product->get_ID();
4
	if ( 'variation' === $product->get_type() ) :
5
		$product_id = $product->get_parent_id();
6
	endif;
7
	if ( has_term( 'stock-offers', 'product_tag', $product_id ) || has_term( 'apple', 'product_brand', $product_id ) ) :
8
		$valid = false;
9
	endif;
10
	return $valid;
11
}
12
add_filter( 'woocommerce_coupon_is_valid_for_product', 'wc_custom_coupon_rules', 10, 4 );

With this rule in place, assuming we have available a welcome10 coupon for a 10% discount, a customer with these selections will enjoy a 2.50€ discount.

An example of a discount ruleAn example of a discount ruleAn example of a discount rule

4. Set a discount only for variable products without the Large size attribute.

To enable this rule, add the following code in the functions.php file of your theme:

1

2
function wc_custom_coupon_rules( $valid, $product, $coupon, $values ) {
3
    if ( 'variation' === $product->get_type() && 'Large' === $product->get_attribute( 'pa_size' ) ) :
4
		$valid = false;
5
	endif;
6
	return $valid;
7
}
8
add_filter( 'woocommerce_coupon_is_valid_for_product', 'wc_custom_coupon_rules', 10, 4 );

With this rule in place, assuming we have available a welcome10 coupon for a 10% discount, a customer with these selections will enjoy a 5€ discount.

An example of a discount ruleAn example of a discount ruleAn example of a discount rule

Conclusion

As you can see, with just a small amount of code, we set custom discount rules for different WooCommerce taxonomies.

You can build on the provided code and customize it according to your needs. For example, you can limit some of these conditions only to certain coupons or make the filter options dynamic by adding new fields in the admin. Nothing stops you from combining your own conditions with the ones that WooCommerce provides by default.

As always, thanks a lot for reading!



Source link

based discounts manage taxonomies tip WooCommerce
Share. Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
Previous ArticlePartner w/ One of These Top 20 Hair Care Influencers
Next Article 26 A/B testing ideas to increase click-through rates and boost conversions
admin
  • Website

Related Posts

How Will AI Impact the Bottom of the Web Design Market? — Speckyboy

March 9, 2026

Human Strategy In An AI-Accelerated Workflow — Smashing Magazine

March 8, 2026

Portfolio Storytelling: How to Present Your Work Like a Narrative

March 7, 2026

Finding New Opportunities for Your WordPress Agency — Speckyboy

March 6, 2026
Leave A Reply Cancel Reply

  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • Vimeo
Don't Miss
Marketing

In and Out of Model Responses Explained — Whiteboard Friday

By adminMarch 10, 20260

So if it doesn’t, then, for example, we might have a query, like “write me…

Balancing Credit Building with Credit Caution

March 10, 2026

How Will AI Impact the Bottom of the Web Design Market? — Speckyboy

March 9, 2026

What Are Secondary Keywords? (And How to Use Them)

March 8, 2026

Subscribe to Updates

Get the latest creative news from Trendswave about Marketing, SEO & Web Design.

Please enable JavaScript in your browser to complete this form.
Loading
About Us

Trendswave is an Influencer Marketing Agency with access to one of the largest influencer networks in the Poland, connecting brands and agencies to only the best influencers and social media thought leaders.

Our Picks

In and Out of Model Responses Explained — Whiteboard Friday

March 10, 2026

Balancing Credit Building with Credit Caution

March 10, 2026
Quicklinks
  • Influencer Marketing
  • Marketing
  • SEO
  • Social Media
  • Web Design
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions
© 2026 Trendswave.All Rights Reserved

Type above and press Enter to search. Press Esc to cancel.