You could also check each product in the cart and restrict it from the coupon with woocommerce_coupon_is_valid_for_product
/**
* exclude a product from an coupon by attribute value
*/
add_filter('woocommerce_coupon_is_valid_for_product', 'exclude_product_from_coupon_by_attribute', 12, 4);
function exclude_product_from_coupon_by_attribute($valid, $product, $coupon, $values ){
/**
* attribute Settings
*/
$taxonomy = 'pa_saison';
$term_slugs = array('SS22');
/**
* check if the product has the attribute and value
* and if yes restrict this product from the coupon
*/
if(in_array($product->get_attribute($taxonomy), $term_slugs)) {
$valid = false;
/**
* otherwise check if its a variation product
*/
} elseif($product->parent_id) {
/**
* set the parent product
*/
$parent = wc_get_product($product->parent_id);
/**
* check if parent has an attribute with this value
*/
if(in_array($parent->get_attribute($taxonomy), $term_slugs)) {
$valid = false;
}
/**
* for all other products which does not have the attribute with the value
* set the coupon to valid
*/
} else {
$valid = true;
}
return $valid;
}
I have tested it on my site and it works as expected.