Adding a coupon code field to your form is useful if you want to allow users to enter a coupon code that automatically deducts the discount amount from the total. You can use Lookup fields to accomplish this by following the directions below.
Step 1: Create form to add coupon code
- Create a form to add your coupon codes and discount amounts. We'll call this the Coupon Code List form.
- Add a Single Line Text field and label it Coupon Code.
- Add a Number field and label it Discount Amount.
- Submit an entry for each coupon code and discount amount that you would like. For example, you could create 10% discount for Black Friday by entering BlackFriday2016 in the Coupon Code field and .10 in the Discount Amount field.
- Create a new form or go to edit an existing form where users will enter the coupon codes and purchase an item.
- Add a Lookup → Single Line Text field and label the field Coupon code.
Set it up to search values from the Coupon Code List → Coupon Code field.
- Add a Number field to the form and label the field Discount Amount.
In the field options, select Default Value and click the search icon to get the Lookup default value settings. Set it up to get values from the Coupon Code List → Discount Amount field. Set it up to watch the Coupon Code Lookup field.
- Open the field options for the field that calculates the total amount due. Select Default Value (Calculation) and click the calculator icon. Your calculation will include something like:
Replace x with the ID of the field that determines the amount due and replace y with the ID of the Discount Amount field.
If the amount is not included in a field, replace [x] with the amount. For example, if the regular price is $100, use 100-(100*). Replace 225 with the ID of the Discount Amount field.
Step 2: Create a form to enter coupon code
You're finished! Now when a user enters a valid coupon code, it will automatically discount the total. If it is not a valid coupon code, the total will not be altered.