WC_Discounts::validate_coupon_sale_items
Ensure coupon is valid for sale items in the list is valid or throw exception.
Method of the class: WC_Discounts{}
No Hooks.
Returns
true|false.
Usage
// protected - for code of main (parent) or child class $result = $this->validate_coupon_sale_items( $coupon );
- $coupon(WC_Coupon) (required)
- Coupon data.
Changelog
| Since 3.2.0 | Introduced. |
WC_Discounts::validate_coupon_sale_items() WC Discounts::validate coupon sale items code WC 10.5.0
protected function validate_coupon_sale_items( $coupon ) {
if ( $coupon->get_exclude_sale_items() ) {
$valid = true;
foreach ( $this->get_items_to_validate() as $item ) {
if ( $item->product && $item->product->is_on_sale() ) {
$valid = false;
break;
}
}
if ( ! $valid ) {
throw new Exception(
sprintf(
/* translators: %s: coupon code */
esc_html__( 'Sorry, coupon "%s" is not valid for sale items.', 'woocommerce' ),
esc_html( $coupon->get_code() )
),
110
);
}
}
return true;
}