How to Generate Bulk Coupon Codes with Gravity Forms
Learn how to easily generate tens, to tens of thousands, of unique coupon codes—for Gravity Forms, WooCommerce, and Easy Digital Downloads.
Coupons are like a charm that pulls in new customers and invites loyal ones back for more. And let’s be real—who doesn’t love a good discount? 🤭
Whether you’re launching a new product with exclusive offers for the first 200 buyers or rewarding long-time clients with special codes, you’ll need multiple, unique coupons to prevent overlap. Creating them by hand would be noble, but totally unnecessary. Let’s explore how to easily generate bulk coupon codes in Gravity Forms—for Gravity Forms, WooCommerce, and Easy Digital Downloads!
Getting started
This article requires the GP Unique ID perk.
Buy Gravity Perks to get this perk plus 46 other premium Gravity Forms plugins!
These are the main tools you’ll need for all three platforms:
- Gravity Forms: We’ll use Gravity Forms as our framework to create coupons.
- Note: If you want to create coupons for your Gravity Forms forms, you will need an Elite or Nonprofit license. More details in the Gravity Forms section.
- GP Unique ID: Fun little perk that will generate unique codes for us.
- Generate Multiple Unique IDs (PHP snippet): Snippet that allows GP Unique ID to run multiple times per form submission.
- Create Coupons (PHP snippet): Snippet that will fire off the coupon generation method for the platform of your choosing, using the codes generated by GP Unique ID as coupon codes.
As you can see, we’ll be dealing with both English and PHP in this article. Don’t worry, I’ll use some interpreter magic to let you know what the computer is saying! 🖥️
Are PHP snippets new to you? Check out our Managing Snippets guide on how and where to install them.
Once you have the perk and both snippets installed, let’s create our coupon generator form. We’ll use the same form for all three examples.
Coupon generator form
Download the finished form here and import it to your site to get started right away.
Unique ID field: For GP Unique ID to run. This is what you’ll use to configure what the newly generated codes will look like. In the General tab, you can choose between numeric, alphanumeric, or sequential codes. In the Advanced tab, you can set the length of the codes and decide if you want to include a prefix and/or a suffix.
Paragraph field: Cozy big text field for codes to be populated into. I recommend setting the Visibility to “Administrative” since this is just a home for the newly generated codes. Mine is named “Multiple IDs.”
Additional field: Gravity Forms requires at least one field to be filled out for the form to be submitted. It can be any field type. If you’re creating coupons for Gravity Forms or Easy Digital Downloads, you can use this as an opportunity for naming your coupons! I used a Drop Down field.
Here’s what my form looks like:
Now that we have a form to generate our coupons, time for the next step.
- Getting started
- Coupon generator form
- Set up Generate Multiple Unique IDs snippet
- Generate coupons in bulk for Gravity Forms
- Generate coupons in bulk for WooCommerce
- Generate coupons in bulk for Easy Digital Downloads
- To sum it up
Set up Generate Multiple Unique IDs snippet
Navigate to where the snippet is installed and paste this configuration right below it. Change the array values to match your form and number of coupons:
new GPUID_Multiple_IDs( array(
'form_id' => 43, // Replace with your coupon generator form ID
'source_field_id' => 1, // Replace with your Unique ID field ID
'target_field_id' => 3, // Replace with your Paragraph field ID
'count' => 5, // Number of unique IDs (subsequently, coupons) to be generated at a time
) );
Observant wizards will notice that there are multiple configuration examples included in the snippet. We’re keeping it simple for this tutorial, focusing on the strictly-necessary ones. If you want to learn additional bells and whistles, like using a Number field to set the amount of codes to be generated, read this tutorial!
Generate coupons in bulk for Gravity Forms
The last tool you’ll need to create coupons for Gravity Forms is the official Coupons add-on, which requires an Elite or Nonprofit license.
Similar to what we did for the Generate Multiple Unique IDs snippet, paste the following configuration under the Create Coupons snippet:
new GW_Create_Coupon( array(
'form_id' => 43, // Replace with your coupon generator form ID
'source_field_id' => 3, // Replace with your Paragraph field ID
'name_field_id' => 4, // Replace with your naming field ID (e.g. Drop Down)
'plugin' => 'gf',
'amount' => 15, // Replace with your desired coupon amount
'type' => 'percentage', // Also accepts 'flat'
) );
Quick snippet breakdown:
'name_field_id'
: Points to the field that will name the coupons. Only parameter not needed for function, just a nice touch.'plugin'
: This snippet generates coupons for Gravity Forms, WooCommerce, and Easy Digital Downloads.'gf'
tells the snippet we’re working with Gravity Forms coupons.'amount'
and'type'
: Both parameters work in tandem to set the discount amount.'amount' => 10
with'type' => 'flat'
means $10 discount, while'amount' => 40
with'type' => 'percentage'
means 40% discount.
Everything is set up and ready! Time to run your coupon generator form.
Depending on the 'count'
number set for Generate Multiple Unique IDs, the form might take a few minutes to finish submitting. During testing, I created ten thousand unique coupons in one go, and I had time to go pour myself some cold brew coffee. ☕ Just let the tab do its thing!
Once it finishes submitting, go to the Coupons add-on located under Gravity Forms in your WordPress sidebar. Voilá!
The snippet supports all other configurations offered by the Coupons add-on, such as usage limit and start and end dates. Check out all the configurations you can set up here!
Generate coupons in bulk for WooCommerce
WooCommerce comes with built-in coupon creation and management tools.
Similar to what we did for the Generate Multiple Unique IDs snippet, paste the following configuration under the Create Coupons snippet:
new GW_Create_Coupon( array(
'form_id' => 43, // Replace with your coupon generator form ID
'source_field_id' => 3, // Replace with your Paragraph field ID
'plugin' => 'wc',
'amount' => 25, // Replace with your desired coupon amount
'type' => 'percent_product', // Also accepts 'fixed_cart', 'percent', 'fixed_product'
/* If using a type that affects a "product", also include the following:
'meta' => array(
'product_ids' => '676', // Replace with your product ID
) */
) );
Quick snippet breakdown:
'plugin'
: This snippet generates coupons for Gravity Forms, WooCommerce, and Easy Digital Downloads.'wc'
tells the snippet we’re working with WooCommerce coupons.'amount'
and'type'
: Both parameters work in tandem to set the discount amount.'amount' => 10
with'type' => 'fixed_cart'
means $10 discount applied to the whole cart, while'amount' => 40
with'type' => 'percent_product'
means 40% discount applied to a specific product.
Everything is set up and ready! Time to run your coupon generator form.
Depending on the 'count'
number set for Generate Multiple Unique IDs, the form might take a few minutes to finish submitting. During testing, I created ten thousand unique coupons in one go, and I had time to go pour myself some cold brew coffee. ☕ Just let the tab do its thing!
Once it finishes submitting, go to the Coupons section under Marketing. Voilá!
The snippet supports all other configurations offered by the Coupons feature, such as usage limit and start and end dates. Check out all the configurations you can set up here!
Generate coupons in bulk for Easy Digital Downloads
Easy Digital Downloads comes with a built-in coupon creation and management tool called “Discounts.”
Similar to what we did for the Generate Multiple Unique IDs snippet, paste the following configuration under the Create Coupons snippet:
new GW_Create_Coupon( array(
'form_id' => 43, // Replace with your coupon generator form ID
'source_field_id' => 3, // Replace with your Paragraph field ID
'name_field_id' => 4, // Replace with your naming field ID (e.g. Drop Down)
'plugin' => 'edd',
'amount' => 15, // Replace with your desired coupon amount
'type' => 'percent', // Also accepts 'flat'
) );
Quick snippet breakdown:
'name_field_id'
: Points to the field that will name the coupons. Only parameter not needed for function, just a nice touch.'plugin'
: This snippet generates coupons for Gravity Forms, WooCommerce, and Easy Digital Downloads.'edd'
tells the snippet we’re working with Easy Digital Downloads coupons.'amount'
and'type'
: Both parameters work in tandem to set the discount amount.'amount' => 10
with'type' => 'flat'
means $10 discount, while'amount' => 40
with'type' => 'percent'
means 40% discount.
Everything is set up and ready! Time to run your coupon generator form.
Depending on the 'count'
number set for Generate Multiple Unique IDs, the form might take a few minutes to finish submitting. During testing, I created ten thousand unique coupons in one go, and I had time to go pour myself some cold brew coffee. ☕ Just let the tab do its thing!
Once it finishes submitting, go to Discounts. Voilá!
The snippet supports all other configurations offered by the Coupons feature, such as usage limit and start and end dates. Check out all the configurations you can set up here!
To sum it up
- Create a form for GP Unique ID and the snippets to run.
- Customize coupon codes in the GP Unique ID settings.
- Set how many codes you want to generate at a time with the Generate Multiple Unique IDs snippet.
- Finish coupon configuration with the Create Coupons snippet.
- Profit! (Submit the form.)
If you have any price-slicing questions, let us know in the comments! 🪄
Would you like to learn how to build a raffle or lottery event in Gravity Forms? The process is very similar! Check out this awesome article to learn more.