CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Add Coupon Form (tag pair)

add_coupon_form outputs an HTML form that submits a coupon/voucher code to add_coupon_action.

CartThrob form tags output full HTML forms, so do not nest this tag inside another form tag. If you want coupon input inside checkout submission, add a coupon_code input directly to checkout_form.

See also:

Parameters

This tag has no coupon-specific business parameters.

It supports Global Form Parameters, including return/redirect and validation behavior.

Implementation-backed passthrough form-data parameters include:

  • action
  • secure_return
  • return
  • language

logged_out_redirect is also supported via guarded form-tag behavior.

Variables

This tag parses its body with global CartThrob variables plus form variables (globalVariables(true)).

That includes:

  • cart totals and cart context variables
  • customer/session variables
  • custom_data:* variables
  • form/error variables provided by form builder

See Global Tag Variables.

Conditionals

{if allowed}

Shows content only when the current coupon limit has not been reached.

allowed is set to 0 when both of these are true:

  1. global_coupon_limit is configured.
  2. current applied coupon count is greater than or equal to that limit.

Otherwise, allowed is 1.

{if allowed}
    Enter your code here
{/if}

Form Fields

coupon_code

Text input field for the coupon/voucher code.

<input type="text" name="coupon_code" />

Behavior and Constraints

  1. Submits to add_coupon_action.
  2. Form validation runs through form builder.
  3. On validation failure, posted coupon_code is preserved and form/error variables are returned.
  4. On success, customer info save flow runs, then CartThrob attempts to apply coupon_code.
  5. Duplicate coupon codes are not added.
  6. If global_coupon_limit is 1, adding a new valid code replaces the existing code.

Examples

Basic add-coupon form:

{exp:cartthrob:add_coupon_form return="cart/view_cart"}
    <input type="text" name="coupon_code" />
    <input type="submit" value="Add" />
{/exp:cartthrob:add_coupon_form}

Show the form only when coupons are allowed:

{exp:cartthrob:add_coupon_form return="cart/view_cart"}
    {if allowed}
        <input type="text" name="coupon_code" />
        <input type="submit" value="Add" />
    {if:else}
        Coupon limit reached.
    {/if}
{/exp:cartthrob:add_coupon_form}

Coupon input inside checkout form (alternative pattern):

{exp:cartthrob:checkout_form return="cart/order_complete"}
    <input type="text" name="coupon_code" />
    <input type="submit" value="Checkout" />
{/exp:cartthrob:checkout_form}