Property | Type | Description | |
---|---|---|---|
$cache_group | string | Cache group. | |
$data | array | Data array, with defaults. |
Method | Description | |
---|---|---|
__construct ( mixed $data = '' ) | Coupon constructor. Loads coupon data. | |
add_coupon_message ( integer $msg_code ) | Converts one of the WC_Coupon message/error codes to a message string and. | |
decrease_usage_count ( string $used_by = '' ) | Decrease usage count for current coupon. | |
get_amount ( string $context = 'view' ) : float | Get coupon code. | |
get_code ( string $context = 'view' ) : string | Get coupon code. | |
get_coupon_error ( integer $err_code ) : string | Map one of the WC_Coupon error codes to a message string. | |
get_coupon_message ( integer $msg_code ) : string | Map one of the WC_Coupon message codes to a message string. | |
get_date_created ( string $context = 'view' ) : integer | Get date_created | |
get_date_expires ( string $context = 'view' ) : integer | Get coupon expiration date. | |
get_date_modified ( string $context = 'view' ) : integer | Get date_modified | |
get_description ( string $context = 'view' ) : string | Get coupon description. | |
get_discount_amount ( float $discounting_amount, array | null $cart_item = null, boolean $single = false ) : float | Get discount amount for a cart item. | |
get_discount_type ( string $context = 'view' ) : string | Get discount type. | |
get_email_restrictions ( string $context = 'view' ) : array | Get emails to check customer usage restrictions. | |
get_error_message ( ) : string | Returns the error_message string. | |
get_exclude_sale_items ( string $context = 'view' ) : boolean | If this coupon should exclude items on sale. | |
get_excluded_product_categories ( string $context = 'view' ) : array | Get product categories this coupon cannot not apply to. | |
get_excluded_product_ids ( string $context = 'view' ) : array | Get product IDs that this coupon should not apply to. | |
get_free_shipping ( string $context = 'view' ) : boolean | If this coupon grants free shipping or not. | |
get_generic_coupon_error ( integer $err_code ) : string | Error | Map one of the WC_Coupon error codes to an error string. | |
get_individual_use ( string $context = 'view' ) : boolean | Get the "indvidual use" checkbox status. | |
get_limit_usage_to_x_items ( string $context = 'view' ) : integer | Usage limited to certain amount of items | |
get_maximum_amount ( string $context = 'view' ) : float | Get maximum spend amount. | |
get_minimum_amount ( string $context = 'view' ) : float | Get minium spend amount. | |
get_product_categories ( string $context = 'view' ) : array | Get product categories this coupon can apply to. | |
get_product_ids ( string $context = 'view' ) : array | Get product IDs this coupon can apply to. | |
get_usage_count ( string $context = 'view' ) : integer | Get coupon usage count. | |
get_usage_limit ( string $context = 'view' ) : integer | Get coupon usage limit. | |
get_usage_limit_per_user ( string $context = 'view' ) : integer | Get coupon usage limit per customer (for a single customer) | |
get_used_by ( string $context = 'view' ) : array | Get records of all users who have used the current coupon. | |
increase_usage_count ( string $used_by = '' ) | Increase usage count for current coupon. | |
is_type ( string $type ) : boolean | Checks the coupon type. | |
is_valid ( ) : boolean | Check if a coupon is valid. | |
is_valid_for_cart ( ) : boolean | Check if a coupon is valid. | |
is_valid_for_product ( WC_Product $product, $values = [] ) : boolean | Check if a coupon is valid for a product. | |
read_manual_coupon ( string $code, array $coupon ) | Developers can programically return coupons. This function will read those values into our WC_Coupon class. | |
set_amount ( float $amount ) | Set amount. | |
set_code ( string $code ) | Set coupon code. | |
set_date_created ( string $timestamp ) | Set date_created | |
set_date_expires ( string $timestamp ) | Set expiration date. | |
set_date_modified ( string $timestamp ) | Set date_modified | |
set_description ( string $description ) | Set coupon description. | |
set_discount_type ( string $discount_type ) | Set discount type. | |
set_email_restrictions ( array $emails = [] ) | Set email restrictions. | |
set_exclude_sale_items ( boolean $exclude_sale_items ) | Set if this coupon should excluded sale items or not. | |
set_excluded_product_categories ( array $excluded_product_categories ) | Set the product category IDs this coupon cannot be used with. | |
set_excluded_product_ids ( array $excluded_product_ids ) | Set the product IDs this coupon cannot be used with. | |
set_free_shipping ( boolean $free_shipping ) | Set if this coupon enables free shipping or not. | |
set_individual_use ( boolean $is_individual_use ) | Set if this coupon can only be used once. | |
set_limit_usage_to_x_items ( integer $limit_usage_to_x_items ) | Set usage limit to x number of items. | |
set_maximum_amount ( float $amount ) | Set the maximum spend amount. | |
set_minimum_amount ( float $amount ) | Set the minimum spend amount. | |
set_product_categories ( array $product_categories ) | Set the product category IDs this coupon can be used with. | |
set_product_ids ( array $product_ids ) | Set the product IDs this coupon can be used with. | |
set_usage_count ( integer $usage_count ) | Set how many times this coupon has been used. | |
set_usage_limit ( integer $usage_limit ) | Set the amount of times this coupon can be used. | |
set_usage_limit_per_user ( integer $usage_limit ) | Set the amount of times this coupon can be used per user. | |
set_used_by ( array $used_by ) | Set which users have used this coupon. |
Method | Description | |
---|---|---|
get_hook_prefix ( ) : string | Prefix for action and filter hooks on data. |
Method | Description | |
---|---|---|
validate_cart_excluded_items ( ) | Cart discounts cannot be added if non-eligble product is found in cart. | |
validate_cart_excluded_product_categories ( ) | Exclude categories from cart. | |
validate_cart_excluded_product_ids ( ) | Exclude products from cart. | |
validate_cart_excluded_sale_items ( ) | Exclude sale items from cart. | |
validate_excluded_items ( ) | All exclusion rules must pass at the same time for a product coupon to be valid. | |
validate_exists ( ) | Ensure coupon exists or throw exception. | |
validate_expiry_date ( ) | Ensure coupon date is valid or throw exception. | |
validate_maximum_amount ( ) | Ensure coupon amount is valid or throw exception. | |
validate_minimum_amount ( ) | Ensure coupon amount is valid or throw exception. | |
validate_product_categories ( ) | Ensure coupon is valid for product categories in the cart is valid or throw exception. | |
validate_product_ids ( ) | Ensure coupon is valid for products in the cart is valid or throw exception. | |
validate_sale_items ( ) | Ensure coupon is valid for sale items in the cart is valid or throw exception. | |
validate_usage_limit ( ) | Ensure coupon usage limit is valid or throw exception. | |
validate_user_usage_limit ( integer $user_id ) | Ensure coupon user usage limit is valid or throw exception. |
public __construct ( mixed $data = '' ) | ||
$data | mixed | Coupon data, object, ID or code. |
public add_coupon_message ( integer $msg_code ) | ||
$msg_code | integer | Message/error code. |
public decrease_usage_count ( string $used_by = '' ) | ||
$used_by | string | Either user ID or billing email |
public get_amount ( string $context = 'view' ) : float | ||
$context | string | |
return | float |
public get_coupon_error ( integer $err_code ) : string | ||
$err_code | integer | Message/error code. |
return | string |
public get_coupon_message ( integer $msg_code ) : string | ||
$msg_code | integer | |
return | string |
public get_date_created ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_date_expires ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_date_modified ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_description ( string $context = 'view' ) : string | ||
$context | string | |
return | string |
public get_discount_amount ( float $discounting_amount, array | null $cart_item = null, boolean $single = false ) : float | ||
$discounting_amount | float | Amount the coupon is being applied to |
$cart_item | array | null | Cart item being discounted if applicable |
$single | boolean | True if discounting a single qty item, false if its the line |
return | float | Amount this coupon has discounted |
public get_discount_type ( string $context = 'view' ) : string | ||
$context | string | |
return | string |
public get_email_restrictions ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public get_error_message ( ) : string | ||
return | string |
public get_exclude_sale_items ( string $context = 'view' ) : boolean | ||
$context | string | |
return | boolean |
public get_excluded_product_categories ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public get_excluded_product_ids ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public get_free_shipping ( string $context = 'view' ) : boolean | ||
$context | string | |
return | boolean |
public static get_generic_coupon_error ( integer $err_code ) : string | Error | ||
$err_code | integer | Error code |
return | string | Error |
protected get_hook_prefix ( ) : string | ||
return | string |
public get_individual_use ( string $context = 'view' ) : boolean | ||
$context | string | |
return | boolean |
public get_limit_usage_to_x_items ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_maximum_amount ( string $context = 'view' ) : float | ||
$context | string | |
return | float |
public get_minimum_amount ( string $context = 'view' ) : float | ||
$context | string | |
return | float |
public get_product_categories ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public get_product_ids ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public get_usage_count ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_usage_limit ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_usage_limit_per_user ( string $context = 'view' ) : integer | ||
$context | string | |
return | integer |
public get_used_by ( string $context = 'view' ) : array | ||
$context | string | |
return | array |
public increase_usage_count ( string $used_by = '' ) | ||
$used_by | string | Either user ID or billing email |
public is_valid_for_cart ( ) : boolean | ||
return | boolean |
public is_valid_for_product ( WC_Product $product, $values = [] ) : boolean | ||
$product | WC_Product | |
return | boolean |
public read_manual_coupon ( string $code, array $coupon ) | ||
$code | string | Coupon code |
$coupon | array | Array of coupon properties |
public set_date_created ( string $timestamp ) | ||
$timestamp | string | Timestamp |
public set_date_expires ( string $timestamp ) | ||
$timestamp | string | Timestamp |
public set_date_modified ( string $timestamp ) | ||
$timestamp | string |
public set_description ( string $description ) | ||
$description | string |
public set_discount_type ( string $discount_type ) | ||
$discount_type | string |
public set_email_restrictions ( array $emails = [] ) | ||
$emails | array |
public set_exclude_sale_items ( boolean $exclude_sale_items ) | ||
$exclude_sale_items | boolean |
public set_excluded_product_categories ( array $excluded_product_categories ) | ||
$excluded_product_categories | array |
public set_excluded_product_ids ( array $excluded_product_ids ) | ||
$excluded_product_ids | array |
public set_free_shipping ( boolean $free_shipping ) | ||
$free_shipping | boolean |
public set_individual_use ( boolean $is_individual_use ) | ||
$is_individual_use | boolean |
public set_limit_usage_to_x_items ( integer $limit_usage_to_x_items ) | ||
$limit_usage_to_x_items | integer |
public set_maximum_amount ( float $amount ) | ||
$amount | float |
public set_minimum_amount ( float $amount ) | ||
$amount | float |
public set_product_categories ( array $product_categories ) | ||
$product_categories | array |
public set_product_ids ( array $product_ids ) | ||
$product_ids | array |
public set_usage_count ( integer $usage_count ) | ||
$usage_count | integer |
public set_usage_limit ( integer $usage_limit ) | ||
$usage_limit | integer |
public set_usage_limit_per_user ( integer $usage_limit ) | ||
$usage_limit | integer |
public set_used_by ( array $used_by ) | ||
$used_by | array |