WC_Discounts::validate_coupon_product_ids( WC_Coupon $coupon )
Ensure coupon is valid for products in the list is valid or throw exception.
Description Description
Parameters Parameters
- $coupon
-
(Required) Coupon data.
Return Return
(bool)
Source Source
File: includes/class-wc-discounts.php
protected function validate_coupon_product_ids( $coupon ) {
if ( count( $coupon->get_product_ids() ) > 0 ) {
$valid = false;
foreach ( $this->get_items_to_validate() as $item ) {
if ( $item->product && in_array( $item->product->get_id(), $coupon->get_product_ids(), true ) || in_array( $item->product->get_parent_id(), $coupon->get_product_ids(), true ) ) {
$valid = true;
break;
}
}
if ( ! $valid ) {
throw new Exception( __( 'Sorry, this coupon is not applicable to selected products.', 'woocommerce' ), 109 );
}
}
return true;
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |