Using Coupon Codes to Set Pricing with Gravity Forms

cashregister

I'm sure there must be a better way to do what I've done here, but it was fast and easy and I thought I'd write it up in case others want to suggest alternative approaches.

The Problem

Imagine you want to charge someone for a product or service – but you want the price to be dynamic. Now, just because you want it dynamic doesn't mean you want the customer to set the price. You still want to set it. So you need a way to set it differently for different folks, but also be simple to administrate and keep the supporting technology light.

The Tools

Imagine you want to do this without a full-blown e-commerce solution. And further imagine you have Gravity Forms (the best WordPress plugin ever). And even though I hate Paypal, let's assume a simple payment mechanism so that I can show you what I'm talking about without configuring a more complicated gateway bridge.

Using Coupon Codes

Most people use coupon codes to set discounts. But there's no reason you couldn't set the price using these codes as well. In fact, it makes it easy because people are inclined to use a discount code, and yet here you're letting the discount code determine the price of what you're selling.

Creating the Form

gf1Form

To keep things really simple, I only added four fields. The first was the product (which was set as a calculation type, with a formula that takes its value from the discount code).

gf2producttype

Notice that the formula is really simple – it's the value of the discount code field.

Other than the total and the credit card fields, the only other field is the actual Discount Code field. In this case, I made it a drop down (you could make it anything). You can create as many codes as you like, setting the price for each.

gf3discount

Now, before you close this out, you have to go to the “Advanced” tab to make sure you can pass in the discount codes via the query string.

gf4code

Using & Styling the Form

That makes it easy to visit the page with the ?discountcode=BlueSteel and have the price set automatically at $50. Or, using LeTigre, you could make it free – like here…

gf5letigre

Now, to make this really work, you wouldn't necessarily want to show the Product and DiscountCode fields on the form. But you don't want to hide them using Gravity Form's controls, because then you can't use them to dynamically set the price.

Instead, you want to use CSS – to make these fields invisible. Now, I know what you're thinking – just put “Display: none;” right?  Here's why you may not want to do that and alternative approaches.

And if you need help knowing exactly what CSS classes to target, here's a great Gravity Forms resource.

Additional Resources

Now, I've done something here that's pretty simple and plain. But it looks like there's some code over on GitHub that may be doing real coupons for Gravity Forms. If that's the case, you'll want to check them out.