Coupon Codes

This document is for a version of Craft Commerce that is no longer supported. Please refer to the latest version →

Coupon codes are set up as a condition within a discount promotion.

To create a new discount, go to CommercePromotionsDiscounts in the control panel. To see the coupon condition, go to the “Coupon” tab.

Discounts are only available in the Pro edition of Craft Commerce.

An empty coupon field on the discount means there is no requirement for a coupon for the discount to work. Adding a coupon requires that a coupon is submitted to the cart. This makes the discount available to match the order but still needs to match all other discount conditions.

Read more about Discounts.

# Using a coupon

To add a coupon to the cart, a customer submits the couponCode parameter to the cart using the commerce/cart/update-cart form action.

Example:

<form method="post">
  <input type="hidden" name="action" value="commerce/cart/update-cart">
  <input type="hidden" name="cartUpdatedNotice" value="Added coupon code.">
  {{ redirectInput('shop/cart') }}
  {{ csrfInput() }}

  <input type="text"
         name="couponCode"
         value="{{ cart.couponCode }}"
         class="{% if cart.getFirstError('couponCode') %}has-error{% endif %}"
         placeholder="{{ "Coupon Code"|t }}"
  >

  <input type="submit" value="Update Cart"/>
</form>

Only one coupon code can exist on the cart at a time. The current coupon code submitted to the cart can be seen by outputting {{ cart.couponCode }}.

You can retrieve the discount associated with the coupon code with:

{% set discount = craft.commerce.discounts.getDiscountByCode(cart.couponCode) %}
{% if discount %}
  {{ discount.name }} - {{ discount.description }}
{% endif %}