woocommerce_coupon_is_valid_for_excluded_items
Filter whether the coupon is valid for the cart given its excluded items.
Return true to treat the coupon as valid, or false to reject it. Mind the polarity: these woocommerce_coupon_is_valid_for_ filters follow the woocommerce_coupon_is_valid convention where true means valid. This is the opposite of the woocommerce_coupon_validate_ filters (e.g. woocommerce_coupon_validate_expiry_date), where returning true rejects the coupon.
Usage
add_filter( 'woocommerce_coupon_is_valid_for_excluded_items', 'wp_kama_woocommerce_coupon_is_valid_for_excluded_items_filter', 10, 3 );
/**
* Function for `woocommerce_coupon_is_valid_for_excluded_items` filter-hook.
*
* @param bool $valid Whether the coupon is valid given the cart's exclusion rules.
* @param WC_Coupon $coupon Coupon data.
* @param WC_Discounts $discounts The discounts instance.
*
* @return bool
*/
function wp_kama_woocommerce_coupon_is_valid_for_excluded_items_filter( $valid, $coupon, $discounts ){
// filter...
return $valid;
}
- $valid(true|false)
- Whether the coupon is valid given the cart's exclusion rules.
- $coupon(WC_Coupon)
- Coupon data.
- $discounts(WC_Discounts)
- The discounts instance.
Changelog
| Since 11.1.0 | Introduced. |
Where the hook is called
woocommerce_coupon_is_valid_for_excluded_items
woocommerce/includes/class-wc-discounts.php 984
$valid = apply_filters( 'woocommerce_coupon_is_valid_for_excluded_items', $valid, $coupon, $this );