How to Setup and Use a Coupon Code with Ninja Forms

Sales, discounts, membership pricing, affiliate deals- these types of offers are a common part of many business’ sales strategies, and coupon codes are a popular means of applying those offers. If you’re looking at how to use a coupon code with Ninja Forms, it’s a walk in the park once you know how. Become a master of coupon code discounts right now! Just follow along for the next few minutes and we’ll show you how!

What Do I Need?

2 simple things:

A Coupon Code with Ninja Forms Demo

I’ll start by showing you a simple but functional form I built to sell Widgets. The form you want to use will probably (hopefully!) look totally different, and that’s just fine. What you see below is only a proof of concept.

The user can apply the coupon code “Charlie” in this form to receive a 50% discount off of their total. Remember, you can use a coupon code with any type, shape, or flavor of form you desire. It doesn’t have to look exactly like this. That’s a good thing, because there are species of small monkeys that make better designers than me.

My ugly Widget sales form:

coupon code for ninja forms demo 1

So now, if a customer wants 3 Widgets at $10 a Widget, that’s going to run him $30. You can see that both the subtotal and total reflect that value:

coupon code for ninja forms demo 2

But! We’re running a sale with the coupon code Charlie. Let’s apply that code:

coupon code for ninja forms demo 3

As you can see, it’s applied a .5 or 50% discount and reduced the total accordingly. The Discount field (a calculation field) is necessary to make the coupon code work, so I wanted you to see it here, but it doesn’t have to be visible to the user if you’d prefer.

Let’s look now behind the scenes at the nuts and widgets, er… bolts, of getting your coupon code working.

Form Builder Nuts and Bolts

Ok, here’s what we’re working with on the backend. The only fields that I’ve adjusted to make the coupon code work are circled:

coupon code for ninja forms form builder view

The basic fields you need are:

  • A textbox field for the user to enter the actual coupon code into. I’ve named this field Coupon Code.
  • A calculation field that stores the discount amount and applies it conditionally if and only if the coupon code is entered
  • A total field that factors in the discount amount if and only if it has been conditionally applied by the calculation field.

Let’s walk through the steps to set it all up now!

Setting Up Your Coupon Code with Ninja Forms

1) Add a textbox, calculation, and total field to the form.

2) Expand the calculation field to see the field settings. We’re going to apply conditional logic to this field, so expand the Conditional Logic Settings at the bottom of the field as well (if you don’t see this setting, you need to install/activate Conditional Logic).

3) Add a conditional statement to the calculation field.

  • Set the action to Change Value, and the value itself to the amount of discount you want applied. I wanted a 50% discount, so I entered .5
  • “If” can be set to All or Any, depending on the number of coupon codes you’ll have for this discount amount.
  • Set Field equal to the textbox field that the user will enter the coupon code into. In this example I’ve named that textbox field Coupon Code.
  • Set that field as “Equal To”
  • Enter the value of the field as your coupon code. I’ve named mine Charlie.

Now if a customer enters Charlie into the Coupon Code field, the value of the calculation field will change from the default of 1 to .5, and we’ll make use of that in the next and final step.

coupon code for ninja forms conditional statement

4) Expand the field setting of the total field. The Calculation Method you use can and will vary depending on your needs. The fields you incorporate into the total will of course also vary by your needs. The key here is to incorporate the calculation field you’re using into the total so that the coupon code discount can be applied.

If you’re using a percentage like I am here, you’ll want to multiply by the calculation field. If it’s a flat $5 off, you’d want to set the calculation field’s conditional value to 5 and then in the total field, subtract the calculation field in your equation. You can see how I’ve set mine up to apply the 50% discount:

coupon code for ninja forms total field calculation method

It just grabs the subtotal and multiplies it by the value of the calculation field (Discount). If no coupon code is entered, it multiplies the subtotal by the default calculation field value of 1. If Charlie has been entered, then the value of the calculation field changes to .5 and the subtotal is multiplied by that instead.

That’s a Wrap!

And that’s the process. At a glance it looks complicated, and there is a small learning curve to it. You’ll find that after you’ve set it up once though, it’s actually really easy. Remember, the process can be as flexible as you need it to be. You can allow for multiple coupon codes by adding additional criteria to the conditional statement of the calculation field, you can discount as a percent or by flat values, etc etc.

One final note: if this makes your head spin just a little, Conditional Logic is in the process of being upgraded to Ninja Forms THREE compatibility right now. It’s a thing of beauty, and simplifies this process quite a bit. Keep your eyes peeled! For now, if you have questions please feel free to fire away in the comments below!