woocommerce_coupon_is_valid_for_excluded_product_ids
Filter whether the coupon is valid for the cart given its excluded_product_ids 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. When rejecting, use the woocommerce_coupon_error filter (error code WC_Coupon::E_WC_COUPON_EXCLUDED_PRODUCTS) to customize the message shown to the shopper.
Использование
add_filter( 'woocommerce_coupon_is_valid_for_excluded_product_ids', 'wp_kama_woocommerce_coupon_is_valid_for_excluded_product_ids_filter', 10, 3 );
/**
* Function for `woocommerce_coupon_is_valid_for_excluded_product_ids` filter-hook.
*
* @param bool $valid Whether the coupon is valid given the excluded products.
* @param WC_Coupon $coupon Coupon data.
* @param WC_Discounts $discounts The discounts instance.
*
* @return bool
*/
function wp_kama_woocommerce_coupon_is_valid_for_excluded_product_ids_filter( $valid, $coupon, $discounts ){
// filter...
return $valid;
}
- $valid(true|false)
- Whether the coupon is valid given the excluded products.
- $coupon(WC_Coupon)
- Coupon data.
- $discounts(WC_Discounts)
- The discounts instance.
Список изменений
| С версии 11.1.0 | Введена. |
Где вызывается хук
woocommerce_coupon_is_valid_for_excluded_product_ids
woocommerce/includes/class-wc-discounts.php 1055
$valid = apply_filters( 'woocommerce_coupon_is_valid_for_excluded_product_ids', $valid, $coupon, $this );