WC_Discounts::validate_coupon_excluded_product_ids
Exclude products.
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_excluded_product_ids( $coupon );
- $coupon(WC_Coupon) (required)
- Coupon data.
Changelog
| Since 3.2.0 | Introduced. |
WC_Discounts::validate_coupon_excluded_product_ids() WC Discounts::validate coupon excluded product ids code WC 10.5.0
protected function validate_coupon_excluded_product_ids( $coupon ) {
// Exclude Products.
if ( count( $coupon->get_excluded_product_ids() ) > 0 ) {
$products = array();
foreach ( $this->get_items_to_validate() as $item ) {
if ( $item->product && in_array( $item->product->get_id(), $coupon->get_excluded_product_ids(), true ) || in_array( $item->product->get_parent_id(), $coupon->get_excluded_product_ids(), true ) ) {
$products[] = $item->product->get_name();
}
}
if ( ! empty( $products ) ) {
throw new Exception(
sprintf(
/* translators: %1$s: coupon code, %2$s: products list */
esc_html__( 'Sorry, coupon "%1$s" is not applicable to the products: %2$s.', 'woocommerce' ),
esc_html( $coupon->get_code() ),
esc_html( implode( ', ', $products ) )
),
113
);
}
}
return true;
}