woocommerce_coupon_is_valid_for_sale_items │ filter-hook │ WC 11.1.0

Filter whether the coupon is valid for the cart given its sale_items restriction.

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_sale_items', 'wp_kama_woocommerce_coupon_is_valid_for_sale_items_filter', 10, 3 );

/**
 * Function for `woocommerce_coupon_is_valid_for_sale_items` filter-hook.
 * 
 * @param bool         $valid     Whether the coupon is valid given the sale items in the cart.
 * @param WC_Coupon    $coupon    Coupon data.
 * @param WC_Discounts $discounts The discounts instance.
 *
 * @return bool
 */
function wp_kama_woocommerce_coupon_is_valid_for_sale_items_filter( $valid, $coupon, $discounts ){
	// filter...
	return $valid;
}
$valid(true|false)
Whether the coupon is valid given the sale items in the cart.
$coupon(WC_Coupon)
Coupon data.
$discounts(WC_Discounts)
The discounts instance.

Changelog

Since 11.1.0 Introduced.

Where the hook is called

WC_Discounts::validate_coupon_sale_items()
woocommerce_coupon_is_valid_for_sale_items
woocommerce/includes/class-wc-discounts.php 934
$valid = apply_filters( 'woocommerce_coupon_is_valid_for_sale_items', $valid, $coupon, $this );

Where the hook is used in WooCommerce

Usage not found.