Creating Coupons for Easy Digital Downloads with Gravity Forms
Create coupons for Easy Digital Downloads dynamically from Gravity Forms submissions.
Coupons are a useful incentive for persuading customers to fill out a form.
Want to encourage visitors to sign up for your newsletter? Offer them a coupon code for a small discount at your shop.
Trying to spread the word about your online store? Insert a “Share this Product with a Friend” form on your site and send the sharer a discount for use on their first purchase.
This snippet also supports creating coupons for WooCommerce and Gravity Forms. Check out these awesome articles:
– Creating Coupons for WooCommerce with Gravity Forms
– Creating Coupons for GF Coupons Add-on with Gravity Forms
Getting Started
- Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Make sure you have Gravity Forms installed and activated.
- Install the snippet
- Copy and paste the entire snippet into your theme’s functions.php file.
- Configure the snippet
- The basic configuration only requires that you specify the which form should be used to generate coupons (
form_id
), which field’s value should be used as the coupon code (source_field_id
), and thetype
andamount
of the coupon. - See the Usage Examples and available Parameters below.
- The basic configuration only requires that you specify the which form should be used to generate coupons (
Check out How to Generate Bulk Coupon Codes with Gravity Forms to learn how to create multiple discounts at a time.
Usage Examples
Easy Digital Downloads Coupon with Flat Discount, Applied to Cart
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'edd',
'amount' => 10,
'type' => 'flat'
) );
Creates a flat $10 discount that applies to the entire cart. Whenever Form ID 608 is submitted, the value of Field ID 1 is used to create a new coupon.
Easy Digital Downloads Coupon with Percentage Discount, Applied to Cart
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'edd',
'amount' => 10,
'type' => 'percent'
) );
Creates a 10% discount that applies to the entire cart.
Easy Digital Downloads Coupon with Percentage Discount, Applied to Specific Product(s)
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'edd',
'amount' => 10,
'type' => 'percent',
'meta' => array(
'product_reqs' => '123',
'is_not_global' => true,
)
) );
Creates a 10% discount that applies only to product ID 123 (via a combination of product_reqs and is_not_global).
Easy Digital Downloads Coupon with Percentage Discount, Applied to Entire Cart When Cart Contains a Specific Product
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'edd',
'amount' => 10,
'type' => 'percent',
'meta' => array(
'product_reqs' => '123',
)
) );
Creates a 10% discount that applies to entire cart. Discount is only applied when cart contains a specific product (handled by product_reqs).
Easy Digital Downloads Coupon with Usage Limit and Expiration Date
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'edd',
'amount' => 10,
'type' => 'flat',
'meta' => array(
'max_uses' => 5,
'expiration' => '12/31/2020'
)
) );
Creates a flat $10 discount that applies to the entire cart. The coupon can be used up to 5 times (handled by the max_uses) and will expire on December 31, 2020 (via the expiration).
Easy Digital Downloads Coupon with Name Set by Field Value
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'name_field_id' => 20,
'plugin' => 'edd',
'amount' => 15,
'type' => 'flat',
) );
Creates a 15% discount that applies to the entire cart. This coupon’s title is derived from the value in Field 20 (handled by name_field_id).
Parameters
Here is a full list of the available parameters and additional information on how each can be configured.
new GW_Create_Coupon( array(
'form_id' => 608,
'source_field_id' => 1,
'name_field_id' => 20,
'plugin' => 'edd',
'amount' => 15,
'type' => 'flat',
'meta' => array(
'excluded_products' => array(),
'expiration' => '',
'is_not_global' => false,
'is_single_use' => false,
'max_uses' => '',
'min_price' => '',
'product_reqs' => array(),
'start' => '',
)
) );
<
ul>
The ID of the form which will be used to create coupons on submission.
The ID of the field whose value will be used as the coupon code.
The ID of the field whose value will be used as the coupon title.
The plugin for which you would like to generated a coupon. WooCommerce (
'wc'
), Easy Digital Downloads ('edd'
), and Gravity Forms ('gf'
) are currently supported.The amount the generated coupon should discount.
The type of coupon. Supported values are:
'flat' | Applies a flat discount to the entire cart. |
'percent' | Applies a percentage discount to the entire cart. |
An array of additional options that can be used to customize the generated coupon.
excluded_products | A comma-delimited list of products (by ID) which the coupon will not apply to. |
expiration | Specify the date when the coupon expires. Format: 'MM/DD/YYYY' . Example: 12/31/2020 |
is_not_global | Set to true if the coupon is applied only to products set in product_reqs. |
is_single_use | Set to 'yes' if the coupon should be limited to a single use per customer. |
max_uses | Set how many times this coupon can be used before it is void. Default value is 1 . Set to '' for unlimited usage. |
min_price | Set the minimum subtotal needed to use the coupon. |
product_reqs | A comma-delimited list of products (by ID) which need to be in the cart to use this coupon or, for “Product Discounts”, which products are discounted. |
start | The coupon start date. Format: 'MM/DD/YYYY' . Example: 12/31/2020 . Leave blank if there is no coupon start date. |
How’d we do?
If you use it and like it, let us know. We’d love to hear the different ways you found this code useful!