Class WC_Coupon

WooCommerce coupons

The WooCommerce coupons class gets coupon data from storage and checks coupon validity

Package: WooCommerce\Classes
Category: Class
Author: WooThemes
Class: WC_Coupon
Located at includes/class-wc-coupon.php

Methods summary

public
# __construct( mixed $code )

Coupon constructor. Loads coupon data.

Coupon constructor. Loads coupon data.

Parameters

$code
mixed
$code code of the coupon to load
public boolean
# apply_before_tax( )

Check if coupon needs applying before tax.

Check if coupon needs applying before tax.

Returns

boolean
public boolean
# enable_free_shipping( )

Check if a coupon enables free shipping.

Check if a coupon enables free shipping.

Returns

boolean
public boolean
# exclude_sale_items( )

Check if a coupon excludes sale items.

Check if a coupon excludes sale items.

Returns

boolean
public
# inc_usage_count( string $used_by = '' )

Increase usage count fo current coupon.

Increase usage count fo current coupon.

Parameters

$used_by
string
$used_by Either user ID or billing email
public
# dcr_usage_count( string $used_by = '' )

Decrease usage count fo current coupon.

Decrease usage count fo current coupon.

Parameters

$used_by
string
$used_by Either user ID or billing email
public string
# get_error_message( )

Returns the error_message string

Returns the error_message string

Returns

string
public boolean|WP_Error
# is_valid( )

is_valid function.

is_valid function.

Check if a coupon is valid. Return a reason code if invalid. Reason codes:

Returns

boolean|WP_Error
validity or a WP_Error if not valid
public boolean
# is_valid_for_cart( )

Check if a coupon is valid

Check if a coupon is valid

Returns

boolean
public boolean
# is_valid_for_product( WC_Product $product )

Check if a coupon is valid for a product

Check if a coupon is valid for a product

Parameters

$product
WC_Product
$product

Returns

boolean
public float
# get_discount_amount( float $discounting_amount, array|null $cart_item = null, boolean $single = false )

Get discount amount for a cart item

Get discount amount for a cart item

Parameters

$discounting_amount
float
$discounting_amount Amount the coupon is being applied to
$cart_item
array|null
$cart_item Cart item being discounted if applicable
$single
boolean
$single True if discounting a single qty item, false if its the line

Returns

float
Amount this coupon has discounted
public
# add_coupon_message( integer $msg_code )

Converts one of the WC_Coupon message/error codes to a message string and displays the message/error.

Converts one of the WC_Coupon message/error codes to a message string and displays the message/error.

Parameters

$msg_code
integer
$msg_code Message/error code.
public string|
# get_coupon_message( mixed $msg_code )

Map one of the WC_Coupon message codes to a message string

Map one of the WC_Coupon message codes to a message string

Parameters

$msg_code
mixed
$msg_code

Returns

string|
Message/error string
public string|
# get_coupon_error( integer $err_code )

Map one of the WC_Coupon error codes to a message string

Map one of the WC_Coupon error codes to a message string

Parameters

$err_code
integer
$err_code Message/error code.

Returns

string|
Message/error string
public static string|
# get_generic_coupon_error( integer $err_code )

Map one of the WC_Coupon error codes to an error string No coupon instance will be available where a coupon does not exist, so this static method exists.

Map one of the WC_Coupon error codes to an error string No coupon instance will be available where a coupon does not exist, so this static method exists.

Parameters

$err_code
integer
$err_code Error code

Returns

string|
Error string

Magic methods summary

Constants summary

integer E_WC_COUPON_INVALID_FILTERED 100
#
integer E_WC_COUPON_INVALID_REMOVED 101
#
integer E_WC_COUPON_NOT_YOURS_REMOVED 102
#
integer E_WC_COUPON_ALREADY_APPLIED 103
#
integer E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY 104
#
integer E_WC_COUPON_NOT_EXIST 105
#
integer E_WC_COUPON_USAGE_LIMIT_REACHED 106
#
integer E_WC_COUPON_EXPIRED 107
#
integer E_WC_COUPON_MIN_SPEND_LIMIT_NOT_MET 108
#
integer E_WC_COUPON_NOT_APPLICABLE 109
#
integer E_WC_COUPON_NOT_VALID_SALE_ITEMS 110
#
integer E_WC_COUPON_PLEASE_ENTER 111
#
integer WC_COUPON_SUCCESS 200
#
integer WC_COUPON_REMOVED 201
#

Properties summary

public mixed $code
#

Public

string Coupon code.
public mixed $id
#

Public

int Coupon ID.
public mixed $type
#

Public

string Type of discount.
public mixed $discount_type
#

Public

string Type of discount (alias).
public mixed $amount
#

Public

string Coupon amount.
public mixed $individual_use
#

Public

string "Yes" if for individual use.
public mixed $product_ids
#

Public

array Array of product IDs.
public mixed $usage_limit
#

Public

int Coupon usage limit.
public mixed $usage_limit_per_user
#

Public

int Coupon usage limit per user.
public mixed $limit_usage_to_x_items
#

Public

int Coupon usage limit per item.
public mixed $usage_count
#

Public

int Coupon usage count.
public mixed $expiry_date
#

Public

string Expiry date.
public mixed $apply_before_tax
#

Public

string "yes" if applied before tax.
public mixed $free_shipping
#

Public

string "yes" if coupon grants free shipping.
public mixed $product_categories
#

Public

array Array of category ids.
public mixed $exclude_product_categories
#

Public

array Array of category ids.
public mixed $exclude_sale_items
#

Public

string "yes" if coupon does NOT apply to items on sale.
public mixed $minimum_amount
#

Public

string Minimum cart amount.
public mixed $customer_email
#

Public

string Coupon owner's email.
public mixed $coupon_custom_fields
#

Public

array Post meta.
public mixed $coupon_amount
#

Public

string How much the coupon is worth.
public mixed $error_message
#

Public

string Error message.
WooCommerce API documentation generated by ApiGen 2.8.0