1
votes

I am trying to exclude some product variations that have specific product attributes from coupon discounts.

In my case I am targeting product variations that have a product attribute "finish" set to "Classic Frame" or "Box Frame" term.

I tried to use "Exclude variations with 2 specific attribute terms from coupon usage in Woocommerce" answer code and it does indeed make the coupon invalid when a product variation has a product attribute "finish" set to "Classic Frame" or "Box Frame" term.

But it also makes the coupon invalid for any other items added to the cart.

So for example if the cart has 3 items in it:

  • Item 1: has the attribute "Classic Frame" ==> Coupon is Not Valid for this Item
  • Item 2: has the attribute "Box Frame" ==> Coupon is Not Valid for this Item
  • Item 3: has the attribute "Loose" ==> Coupon should be VALID for this Item

So what I would like is that the coupon discount is only applied to other items.

Any help is really appreciated.

1

1 Answers

1
votes

The purpose of "Exclude variations with 2 specific attribute terms from coupon usage in Woocommerce" answer code is to make a coupon invalid if there is any product variation that has 'Classic Frame' or 'Box Frame' term set for 'Finish' product attribute (for variations).

Yes it makes the coupon invalid, even if there is other items without it, and it's the right behavior.

Why?

  • Because (global cart) coupons with a "Percentage discount" or a "Fixed cart discount" don't allow to be applied only to some cart items meaning some product variations and not to others, when using $is_valid property.

  • Same thing if you use the "exclude product IDS" coupon property, as it doesn't handle product variation IDs.

Maybe a commercial plugin exist that extends coupon possibilities, allowing to exclude product variations IDS (adding a usable filter hook) to that extended feature.