Primary

WooCommerce Coupon Shortcodes

This is the documentation page for the WooCommerce Coupon Shortcodes plugin.

Installation

Download the plugin file from the plugin page and install it through your WordPress dashboard under Plugins > Add New. Activate the plugin thereafter.

Shortcodes

The plugin provides a set of shortcodes intended to display information about coupons. There are two classes of shortcodes, conditional shortcodes which display content they enclose based on the validity of one or more coupons, coupon information shortcodes which are used to display the coupon code, description or a discount info derived from the coupon settings.

Each shortcode is described below. The shortcodes allow to specify one or more coupons, note that in some cases it can make sense to specify several codes, but in many cases you would want to indicate only one code.

Please make sure to use the correct syntax in each case.

[coupon_is_applied]

This shortcode covers two usage scenarios:

  • Scenario A – Show content conditionally based on whether certain coupons have been applied to the cart.
  • Scenario B – Show coupon information for applied coupons.

Attributes

  • code : (required) One or more coupon codes, separated by comma, or * to show information for applied coupons.
  • op : (optional) The operation applied to evaluate the validity, and (default) as well as or are accepted. Indicating  op="and" requires all codes to be applied, op="or" requires at least one to be applied.

Example for Scenario A:

[coupon_is_applied code="test"]
This is only displayed if the test coupon is applied to the cart.
[/coupon_is_applied]

Example for Scenario B:

[coupon_is_applied code="*"]
The following discounts have been applied:
[coupon_discount separator="" element_tag="li"]
[/coupon_is_applied]

[coupon_is_not_applied]

This shortcode is similar to the previous one, except it will show content conditionally based on whether a coupon or a set of coupons is not currently applied to the cart.

Note that this shortcode does not allow to indicate a * for the code attribute.

[coupon_is_valid]

This shortcode will display the content it encloses only if the specified coupon codes are currently valid, or alternatively, if one of the coupon codes is valid.

A useful application of this shortcode is to increase a customer’s satisfaction, making her or him aware of the discount applied and increasing the chances of a completed checkout.

Example:

[coupon_is_valid code="test"]
This is only displayed if the test coupon is valid.
[/coupon_is_valid]

Attributes

  • code : (required) one or more coupon codes, separated by comma
  • op : (optional) the operation applied to evaluate the validity, and (default) as well as or are accepted; and requires all codes to be valid, or requires at least one to be valid

[coupon_is_not_valid]

This shortcode will display the content it encloses if the specified coupon codes are currently not valid. It also can be used to display its contents if one of the codes is not valid.

A useful application of this shortcode is to motivate a customer to add items to the cart to obtain the discounts related to the coupons.

Example:

[coupon_is_not_valid code="test"]
This is displayed if the test coupon is not valid.
[/coupon_is_not_valid]

Attributes

  • code : (required) one or more coupon codes, separated by comma
  • op : (optional) the operation applied to evaluate the validity, and (default) as well as or are accepted; and requires allcodes to be invalid, or requires at least one to be invalid

[coupon_enumerate]

This shortcode produces a list of codes that can be used to display information when combined with coupon information shortcodes.

Example:

[coupon_enumerate code="*" type="percent"]
[coupon_discount element_tag="div" prefix="code"]
[/coupon_enumerate]

The above example will produce a list of percentage discount coupons showing the coupon code along with their discount information.

Attributes

  • code : (required) one or more coupon codes, separated by comma, * can be used for all published coupons
  • type : (optional) the coupon type (see below)
  • order : code (default) or ID
  • orderby : ASC (default) or DESC

Allowed types (for the type attribute) :

  • Specific coupon types: fixed_cart, percent, fixed_product, percent_product, sign_up_fee, sign_up_fee_percent, recurring_fee, recurring_percent
  • Coupon type sets: cart, fixed, percent, product, recurring, sign_up, subscription

One or more types can be indicated, separated by comma.

The following shortcodes can be used on their own or within the conditional shortcodes above. If used within [coupon_is_valid] or [coupon_is_not_valid], you do not need to specify the coupon codes again as these shortcodes will be aware of the coupon codes that have been used to evaluate the display condition. This can be an advantage depending on the use case and the number of codes specified.

[coupon_code]

This will display the coupon code(s) as provided through the code attribute. Rather than using this shortcode on its own, it usually makes more sense to use it within one of the conditional shortcodes, as in that case, you don’t need to specify the code(s) again and can use it to display the coupon code to the customer.

Attributes

  • code : one or more coupon codes, separated by comma – only required when used on its own (see above)
  • separator : characters used to separate several codes, defaults to a space

[coupon_description]

This shortcode displays the description(s) of the coupon code(s) specified, or when used within a conditional shortcode without specifying the code attribute, for those coupons indicated with the conditional shortcode.

Attributes

  • code : one or more coupon codes, separated by comma – only required when used on its own (see above)
  • separator : characters used to separate several codes, defaults to a space
  • element_tag : defaults to span, also allows li (the ul will enclose the list), div and p
  • prefix : if code is indicated for this attribute, the coupon codes will be prefixed to the descriptions
  • prefix_separator : defaults to a single space, used when prefix="code" is indicated

[coupon_discount]

This shortcode displays information about the discount related to the coupon. This will be displayed for the coupon code(s) specified, or when used within a conditional shortcode without specifying the code attribute, for those coupons indicated with the conditional shortcode.

The shortcode builds a standardized message for coupons or uses the information provided when the WooCommerce Volume Discount Coupons extension is used.

Attributes

  • code : one or more coupon codes, separated by comma – only required when used on its own (see above)
  • separator : characters used to separate several codes, defaults to a space
  • element_tag : defaults to span, also allows li (the ul will enclose the list), div and p
  • prefix : if code is indicated for this attribute, the coupon codes will be prefixed to the descriptions
  • prefix_separator : defaults to a single space, used when prefix="code" is indicated