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

Driving Qualified Leads With LinkedIn Content: A Proven Formula

October 3, 2025

Google Ads copywriting with AI: Getting the prompt right

October 3, 2025

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025
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

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025

Fresh Resources for Web Designers and Developers (September 2025)

October 2, 2025

Shades Of October (2025 Wallpapers Edition) — Smashing Magazine

October 1, 2025

Principles And Implementation (Part 1) — Smashing Magazine

September 29, 2025
Leave A Reply Cancel Reply

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

Driving Qualified Leads With LinkedIn Content: A Proven Formula

By adminOctober 3, 20250

Are you struggling to generate qualified leads from your LinkedIn content? Wondering how to transform…

Google Ads copywriting with AI: Getting the prompt right

October 3, 2025

A Practical Guide To Building With Clarity (Part 2) — Smashing Magazine

October 3, 2025

Meta unveils Business AI and new generative tools

October 2, 2025

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

Driving Qualified Leads With LinkedIn Content: A Proven Formula

October 3, 2025

Google Ads copywriting with AI: Getting the prompt right

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

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