Cognito Forms logo

How do I create a coupon code?

Friday, July 24, 2015 3:17:00 PM

With the help of some simple calculations, you can use coupon codes to apply discounts on your payment forms. To get started:

1. Add a Textbox field for customers to type in their coupon code:



2. In your Coupon Code field settings, select Show Custom Error - When, and set the error that occurs when customers do not type in the correct code (in this case, "SAVE10"). Make sure to include a custom error message as well ("Invalid code.").


3. Add a Price field labelled Discount (or something similar) to calculate and display the discounted amount. The discount can be a fixed amount, or a percentage based on the total. If your discount is a fixed amount, you can just subtract that number (ex: $5) In the Amount section of the Price field settings:

=if CouponCode = "SAVE10" then -5 else 0

If your discount is based on a percentage, you'll need to multiply the percentage (ex: 10%) by the payment total:

=if CouponCode = "SAVE10" then -ItemTotal* 0.10 else 0

Make sure to update this expression with your own coupon code, discounted percentage, and field names.

The above example is based on an extremely simple payment form. If your order form uses repeating sections, you'll need to sum the total amount from each repeating item rather than just referencing a single Item Total field. You can accomplish this using the .Sum function:

=if CouponCode = "SAVE 10" then -MyOrder.Sum(ItemTotal)*0.10 else 0

Lastly, if you want to apply multiple coupon codes, just add on to your existing calculation like so:

=if CouponCode = "SAVE10" then -ItemTotal* 0.10 else if CouponCode = "SAVE20" then -ItemTotal* 0.20 else 0



Printable View