Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Creating Coupons for Easy Digital Downloads with Gravity Forms

$
0
0

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:

Getting Started

  1. Check requirements
  2. Install the snippet
    • Copy and paste the entire snippet into your theme’s functions.php file.
  3. 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 the type and amount of the coupon.
    • See the Usage Examples and available Parameters below.

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'             => '',
	)
) );
  • 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.
  • name_field_id (integer) (optional)

    The ID of the field whose value will be used as the coupon title.
  • 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.
    'percent'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.

    excluded_productsA comma-delimited list of products (by ID) which the coupon will not apply to.
    expirationSpecify the date when the coupon expires. Format: 'MM/DD/YYYY'. Example: 12/31/2020
    is_not_globalSet to true if the coupon is applied only to products set in product_reqs.
    is_single_useSet to 'yes' if the coupon should be limited to a single use per customer.
    max_usesSet how many times this coupon can be used before it is void. Default value is 1. Set to '' for unlimited usage.
    min_priceSet the minimum subtotal needed to use the coupon.
    product_reqsA 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.
    startThe coupon start date. Format: 'MM/DD/YYYY'. Example: 12/31/2020. Leave blank if there is no coupon start date.

Viewing all articles
Browse latest Browse all 196

Latest Images

Trending Articles



Latest Images