WC_Brands_Coupons::is_valid_for_product()
Check if a coupon is valid for a product.
This allows percentage and product discounts to apply to only the correct products in the cart.
Метод класса: WC_Brands_Coupons{}
Хуков нет.
Возвращает
true|false
. $valid
Использование
$WC_Brands_Coupons = new WC_Brands_Coupons(); $WC_Brands_Coupons->is_valid_for_product( $valid, $product, $coupon );
- $valid(true|false) (обязательный)
- Whether the product should get the coupon's discounts.
- $product(WC_Product) (обязательный)
- WC Product Object.
- $coupon(WC_Coupon) (обязательный)
- Coupon object.
Код WC_Brands_Coupons::is_valid_for_product() WC Brands Coupons::is valid for product WC 9.6.1
public function is_valid_for_product( $valid, $product, $coupon ) { if ( ! is_a( $product, 'WC_Product' ) ) { return $valid; } $this->set_brand_settings_on_coupon( $coupon ); $product_id = $this->get_product_id( $product ); $product_brands = $this->get_product_brands( $product_id ); // Check if coupon has a brand requirement and if this product has that brand attached. $brand_coupon_settings = WC_Brands_Brand_Settings_Manager::get_brand_settings_on_coupon( $coupon ); if ( ! empty( $brand_coupon_settings['included_brands'] ) && empty( array_intersect( $product_brands, $brand_coupon_settings['included_brands'] ) ) ) { return false; } // Check if coupon has a brand exclusion and if this product has that brand attached. if ( ! empty( $brand_coupon_settings['excluded_brands'] ) && ! empty( array_intersect( $product_brands, $brand_coupon_settings['excluded_brands'] ) ) ) { return false; } return $valid; }