3 Easy Steps to Use Coupon Codes in WordPress Forms

Think using WordPress forms to offer coupon codes is complicated? Think again!

Offering coupon codes as a flat or percentage discount is a fantastic way to incentivize your product or service. If you’re selling that product or service through your WordPress forms though, it might look like there’s not an easy way to do it.

You might think this is something only larger commerce plugins can handle- it’s not.

Maybe you’ve tried setting this up through your forms already and found it really complicated.

It can be tough to figure out from scratch, but it’s actually really easy with quick guide. You’ve found that quick guide!

Getting your forms to calculate discount coupon codes is easy! Let’s look at how.

How to Setup Coupon Codes with Your WordPress Forms

We’ll build a quick demo form below to show how this is done. You’ll be able to use the same method in whatever form you already have set up. We’re going to use Conditional Logic to apply the discount rate only when a coupon code is entered, so be sure you have that add-on installed and activated. This will handle either a flat discount or a percentage discount, but we’ll demo a percentage.

Step 1: Add these 3 fields to your form

Here’s our demo form:

Your form will almost certainly look different, but below are the 3 fields you need to add to apply a discount to whatever you’re selling:

  1. Coupon Code. This is a Single Line Text field. Customers enter the coupon code here.
  2. Discount Rate. This is a Hidden field that will contain the discount value.
  3. Total. This is an HTML field. However you’re currently handling your total price, you’ll need to use an HTML field to do this. You’ll see why in a minute.

Before moving on, open your Discount Rate field and:

  • If you’re offering a percentage discount, set the Default Value to 1.
  • If you’re offering a flat discount, set the Default Value to 0.

This will make sense in a minute, I promise. We’re demo’ing a percentage discount, so the Default Value I set here will be 1.

Step 2: Create a single calculation to modify your total

The next step is to create a calculation that will modify the Total with the discount rate of the coupon code. This calculation will use your Product field and your Discount Rate field.

Important: this setup will vary slightly if you’re offering a percentage or a flat discount:

  • If you are offering a percentage discount, you need to MULTIPLY your Product field times your Discount Rate field.
  • If you are offering a flat discount, you need to SUBTRACT your Discount Rate field from your Product field.

To set this up, click on the Advanced tab of your builder and open the Calculations option. Name your calculation, then set up the merge tags for the Product and Discount Rate fields. This is demo’ing a percentage coupon code, so we’re multiplying the two fields:

This calculation will be your total, so open your Total field now and insert the merge tag for the calculation:

Step 3: Set the total to be modified only if a coupon code is entered

Remember setting the Default Value of the Discount Rate field back in Step 1? I told you it would make sense soon. Here’s why.

We only want to modify the total if a coupon code has been entered. We’ve set the calculation for the total as:

  • Product * Discount Rate if you’re offering a percentage discount
  • Product – Discount Rate if you’re offering a flat discount

As we have things set up right now (with no coupon code entered), we’re either multiplying by 1 or subtracting 0. Your total will be unmodified by the calculation this way.

To modify the calculation when a discount code is entered, we need some Conditional Logic. Head over to Advanced > Conditional Logic and add a new condition. Let’s say our coupon code is “coffee” and it’s good for a 25% discount.

Set up the condition like this:

When a user enters “coffee” into the Coupon Code field, the condition will change the value of the Discount Rate field from 1 to .75.

.75 isn’t a typo- to offer a 25% discount, we want to multiply the product total by .75. Yay math! If you’re doing a flat discount, simply put the value of the discount here. $25 off? Enter 25.

Followed these steps? You have working coupon codes for your WordPress forms!

Whether you’re offering a percentage or flat discount with your coupon codes, it’s perfectly doable with your WordPress forms! All you need is the right form builder for the job.

You’ll find the comments below- let us know how you’re using coupon codes with your WordPress website!