WC_Brands_Coupons
in package
WC_Brands_Coupons class.
Important: For internal use only by the Automattic\WooCommerce\Internal\Brands package.
Tags
Table of Contents
- E_WC_COUPON_EXCLUDED_BRANDS = 301
- __construct() : mixed
- Constructor
- brand_exclusion_error() : string
- Display a custom error message when a cart discount coupon does not validate because an excluded brand was found in the cart.
- is_coupon_valid() : bool
- Validate the coupon based on included and/or excluded product brands.
- is_valid_for_product() : bool
- Check if a coupon is valid for a product.
- get_product_brands() : array<string|int, mixed>
- Get a list of brands that are assigned to a specific product
- get_product_id() : int
- Returns the product (or variant) ID.
- set_brand_settings_on_coupon() : void
- Set brand settings as properties on coupon object. These properties are lists of included product brand IDs and list of excluded brand IDs.
Constants
E_WC_COUPON_EXCLUDED_BRANDS
public
mixed
E_WC_COUPON_EXCLUDED_BRANDS
= 301
Methods
__construct()
Constructor
public
__construct() : mixed
Return values
mixed —brand_exclusion_error()
Display a custom error message when a cart discount coupon does not validate because an excluded brand was found in the cart.
public
brand_exclusion_error(string $err, string $err_code) : string
Parameters
- $err : string
-
The error message.
- $err_code : string
-
The error code.
Return values
string —is_coupon_valid()
Validate the coupon based on included and/or excluded product brands.
public
is_coupon_valid(bool $valid, WC_Coupon $coupon[, WC_Discounts $discounts = null ]) : bool
If one of the following conditions are met, an exception will be thrown and displayed as an error notice on the cart page:
- Coupon has a brand requirement but no products in the cart have the brand.
- All products in the cart match the brand exclusion rule.
- For a cart discount, there is at least one product in cart that matches exclusion rule.
Parameters
- $valid : bool
-
Whether the coupon is valid.
- $coupon : WC_Coupon
-
Coupon object.
- $discounts : WC_Discounts = null
-
Discounts object.
Tags
Return values
bool — $valid True if coupon is valid, otherwise Exception will be thrown.is_valid_for_product()
Check if a coupon is valid for a product.
public
is_valid_for_product(bool $valid, WC_Product $product, WC_Coupon $coupon) : bool
This allows percentage and product discounts to apply to only the correct products in the cart.
Parameters
- $valid : bool
-
Whether the product should get the coupon's discounts.
- $product : WC_Product
-
WC Product Object.
- $coupon : WC_Coupon
-
Coupon object.
Return values
bool — $validget_product_brands()
Get a list of brands that are assigned to a specific product
private
get_product_brands(int $product_id) : array<string|int, mixed>
Parameters
- $product_id : int
-
Product id.
Return values
array<string|int, mixed> — brandsget_product_id()
Returns the product (or variant) ID.
private
get_product_id(WC_Product $product) : int
Parameters
- $product : WC_Product
-
WC Product Object.
Return values
int — Product IDset_brand_settings_on_coupon()
Set brand settings as properties on coupon object. These properties are lists of included product brand IDs and list of excluded brand IDs.
private
set_brand_settings_on_coupon(WC_Coupon $coupon) : void
Parameters
- $coupon : WC_Coupon
-
Coupon object.