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 in a WordPress Form

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. You’ll need 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:

ninja forms coupon code form demo with 3 basic fields

 

  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.

The “Choose your plan” field just represents the choice of products/services you’re offering. Whatever it is you’re charging for that you want to apply the discount to. No doubt yours will be different, and that’s fine. The only requirement is that it’s a field that supports calculations. A full list of these fields can be found here.

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, no worries. We’re demo’ing a percentage discount, so the Default Value I set here will be 1.

discount rate field for ninja forms coupon codes with default value set to 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:

calculation in ninja forms that makes it possible to use a coupon code, amount field times discount rate field pictured

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

the calculation's merge tag is pictured being entered into the HTML field labeled "Total"

 

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 to do pick up Conditional Logic or any Ninja Forms membership & follow the steps above.

Comments are below. What other features would you love to see added to Ninja Forms that would help your online storefront?