## 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:

**Coupon Code.**This is a Single Line Text field. Customers enter the coupon code here.**Discount Rate.**This is a Hidden field that will contain the discount value.**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!

## Bobby says:

Great stuff, was just looking up how to do this through Ninja.

One question, can you use multiple codes to generate the same discount? If so how would I set that up?

## Quay Morgan says:

Bobby,

Sure can. Just set up a conditional statement (Step 3) for each code. You can either keep the same rate for each, or vary the rate within the statement.

Cheers,

Quay Morgan

## Kelvin Sim says:

can i set expiry date of coupons?

## Quay Morgan says:

Unfortunately, no. Not right now. We are looking into extra features around this for down the road, though!

## Kellie says:

I’ve set the inilne quantity off. My clients cannot choose more than one product.

There seems to be a missing step. if they do not have coupon code, it Shows the total as $0. Help?

## Quay Morgan says:

Kellie,

Hey! Are you offering a percentage discount? It sounds like you have your Discount Rate field’s Default Value set to 0 rather than 1 (or not set at all). Result would be a total of 0 with no coupon code entered (as the calculation described multiplies the product price * discount rate).

Cheers,

Quay

## Kellie says:

Yes I am offering a percentage discount. This is not the solution, the problem lies in the the product. It is not carrying down to the total. If there is no quantity, The total remains at 0. How do I carry a total if there is no quantity and no discount code.

thank you

## Quay Morgan says:

Ah I see. If you’re using a product field, there must be a quantity attached for the product field to have a value in the calculation. Unless you’re using the inline quantity or a quantity field paired with the product field, this won’t work. You’ll need to think up an alternate way of offering the product, like using a checkbox to acknowledge that they wish to make the purchase. You can give that checkbox a Calc Value equal to the price and replace the product field with that in the calculation.

If you need more help with this, please reach out to us at https://ninjaforms.com/contact/ … ordinarily that’s a much better place for us to troubleshoot difficulties, but posting this response here as you’ve raised a point that might be very helpful for others to read 🙂

## Kellie G says:

Hi again- I do apologize that this should have gone to you as a direct message for trouble shooting.

Just want to let you know, I figured out a workaround! For the product, I set the default value at 1.

I had a customer bypass the payment gateway by not entering a quantity. The product field was zero and payment was not requested. That’s no fun for me!

I do really enjoy Ninja forms, I love working with it. It makes sense to me and it’s easy to use!

Thank you!

## Quay Morgan says:

Kellie,

Absolutely no problem- thank you very much for returning to post your solution, and teaching me something in the process! 🙂

Cheers,

Quay