Submitting a Gravity Form is a powerful thing. After the the submit button is pushed, any number of things could happen. You could register the submitter as a user on your site. You could sign then up to your newsletter or drip campaign. You could sell them a product.
Sometimes users need a little extra push to fill out the form and hit that submit button. This snippet provides a way to dynamically create coupon codes which can be provided to the user for use on a subsequent form. A simple, compelling incentive to submit your form. To share your site. To sign up for your newsletter. To buy your products.
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. Having trouble installing the snippet? Read this.
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 (
Usage Examples
Gravity Form Coupon with Flat Discount, Applied to Cart
View this code snippet on GitHub.Creates a flat $15 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.
Gravity Form Coupon with Percentage Discount, Applied to Cart
View this code snippet on GitHub.Creates a 15% discount that applies to the entire cart.
Stackable Gravity Form Coupon with Usage Limit and Expiration Date
View this code snippet on GitHub.Creates a flat $15 discount that applies to the entire cart. This coupon is can be used with other coupons (we set coupon_stackable to true
). The coupon can be used up to 10 times (handled by the coupon_limit) and will expire on December 31, 2015 (via the coupon_expiration).
Gravity Form Coupon with unlimited use during the month of December 2015
View this code snippet on GitHub.Creates a flat $15 discount that applies to the entire cart. This coupon cannot be used with other coupons (we set coupon_stackable to false
) but it can be used an unlimited number of times (handled by setting coupon_limit to false
) during the month of December 2015 (via the coupon_start and coupon_expiration).
Parameters
Here is a full list of the available parameters and additional information on how each can be configured.
View this code snippet on GitHub.form_id (integer) (required)
The ID of the form which will be used to create coupons on submission.
source_field_id (integer) (required)
The ID of the field whose value will be used as the coupon code.
plugin (string) (required)
The plugin for which you would like to generated a coupon. WooCommerce (
'wc'
), Easy Digital Downloads ('edd'
), and Gravity Forms ('gf'
) are currently supported.amount (integer|float) (required)
The amount the generated coupon should discount.
type (string) (required)
The type of coupon. Supported values are:
'flat'
Applies a flat discount to the entire cart. 'percentage'
Applies a percentage discount to the entire cart. meta (array) (optional)
An array of additional options that can be used to customize the generated coupon.
form_id The ID of the form which the coupon should be usable on. coupon_start The coupon start date. Date format must be MM/DD/YYYY. Leave blank if there is no coupon start date. coupon_expiration The coupon expiration date. Date format must be MM/DD/YYYY. Leave blank if there is no coupon expiration date. coupon_limit Set a number value for how many times this coupon can be used. Defaults to false which will allow it to be used an unlimited number of times. coupon_stackable Set whether the coupon can be used with other coupons. Set to true to allow coupon stacking. Defaults to false.
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!