Primary

WooCommerce Coupon Shortcodes

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

Installation

You can install the plugin directly from within your WordPress dashboard under Plugins > Add New. Search for WooCommerce Coupon Shortcodes by itthinx, install and activate the plugin.

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)
  • orderby : code (default) or IDor rand for random order
  • order : ASC (default) or DESC
  • number : if provided, will limit the number of coupons to the given number

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_show]

This shortcode allows to render the coupon code, its description and its discount info together. It works with the [coupon_enumerate] shortcode if you want to show this information for several codes. For each entry, it will show the information about the code, description and discount together and is thus useful if you want to produce a listing of coupons and their discount. By default, it will render only the coupon code and discount info for each coupon. Here’s an example:

[coupon_enumerate code="*"]
[coupon_show]
[/coupon_enumerate]

The above will list all coupon codes along with their discount info.

The following example will show information about three random coupons, including the coupon code, its description and discount info together on each entry:

[coupon_enumerate code="*" orderby="rand" number="3"]
[coupon_show show="code,description,discount"]
[/coupon_enumerate]

Attributes

  • show : Specify a comma-separated list of information to show for each entry. Valid options are code, discount and description. The default is “code,discount”.
  • code : An list of coupon codes. If used with the [coupon_enumerate] shortcode, this is not required.
  • before : HTML to render before the output is produced. The default is an opening "<div>".
  • after : HTML to render after the output is produced. The default is a  closing "</div>".
  • before_entry : HTML to render before each entry. By default this is the empty string "".
  • after_entry : HTML to render after each entry. By default this is the empty string "".
  • separator : This is output between each aspect rendered within one entry. For example, it will separate the code and discount info. Defaults to a single space " ".

[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