I am trying to get it so the coupons do not work with anything with the attribute of extract-flavor = agave.
There are 2 Extract Flavors Coconut Oil & Agave - I want agave to be invalid with ALL coupons
I have tried the below code, it just makes all coupons invalid
add_filter( 'woocommerce_coupon_is_valid',
'check_if_coupons_are_valid', 10, 3 );
function check_if_coupons_are_valid( $is_valid, $coupon, $discount ){
// YOUR ATTRIBUTE SETTINGS BELOW:
$taxonomy = 'pa_extract-flavor';
$term_slugs = 'agave';
// Loop through cart items and check for backordered items
foreach ( WC()->cart->get_cart() as $cart_item ) {
foreach( $cart_item['variation'] as $attribute => $term_slug ) {
if( $attribute === 'attribute_'.$taxonomy ) {
$is_valid = false; // attribute found, coupons are not valid
break; // Stop and exit from the loop
}
}
}
return $is_valid;
}
I expect it to make all coupons being used on the extract flavors that is agave invalid, but it makes all coupons invalid on all products
thanks