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

How to build an email list without a website in under 5 minutes

September 20, 2026

Is Earned Search Still Worth It?

September 20, 2026

Planning for Deepavali? Indian Creators in Singapore to Watch in 2026

September 20, 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

Claude Code’s Projects beta lets Claude manage the other Claudes

September 19, 2026

23 Handpicked Creative Resume PowerPoint Templates

September 18, 2026

Stop Treating CSS Container Queries Like Traditional Media Queries — Smashing Magazine

September 16, 2026

23 Awesome Arcade Fonts for Retro Gaming Projects

September 15, 2026
Leave A Reply Cancel Reply

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

How to build an email list without a website in under 5 minutes

By adminSeptember 20, 20260

By Jill Fanslau June 10, 2026 Your list is powerful. Think of it as a…

Is Earned Search Still Worth It?

September 20, 2026

Planning for Deepavali? Indian Creators in Singapore to Watch in 2026

September 20, 2026

What is agentic SEO? 8 workflows run on a live site

September 20, 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

How to build an email list without a website in under 5 minutes

September 20, 2026

Is Earned Search Still Worth It?

September 20, 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.