Create Coupons with Gravity Forms for Gravity Forms
Instructions
See “Where do I put snippets?” in our documentation for installation instructions.
Read the Walkthrough
Code
Filename: gw-create-coupons-gf-usage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Gravity Wiz // Gravity Forms // Create Coupons with Gravity Forms for Gravity Forms
* https://gravitywiz.com/creating-coupons-for-gf-coupons-add-on-with-gravity-forms/
*/
// Coupon with Flat Discount, Applied to Total
new GW_Create_Coupon(
array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'gf',
'amount' => 15,
'type' => 'flat',
)
);
// Coupon with Percentage Discount, Applied to Total
new GW_Create_Coupon(
array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'gf',
'amount' => 15,
'type' => 'percentage',
)
);
// Stackable Coupon with Usage Limit and Expiration Date
new GW_Create_Coupon(
array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'gf',
'amount' => 15,
'type' => 'flat',
'meta' => array(
'form_id' => 620,
'coupon_stackable' => true,
'coupon_limit' => 10,
'coupon_expiration' => '12/31/2015',
),
)
);
// Unlimited Use Coupon during the month of December 2015 using Coupon Start and Coupon Expiration
new GW_Create_Coupon(
array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'gf',
'amount' => 15,
'type' => 'flat',
'meta' => array(
'form_id' => 620,
'coupon_stackable' => false,
'coupon_limit' => false,
'coupon_start' => '12/1/2015',
'coupon_expiration' => '12/31/2015',
),
)
);
// All the things!
new GW_Create_Coupon(
array(
'form_id' => 608,
'source_field_id' => 1,
'plugin' => 'gf',
'amount' => 15,
'type' => 'flat', // accepts: 'flat', 'percentage'
'meta' => array(
'form_id' => false,
'coupon_start' => '', // MM/DD/YYYY
'coupon_expiration' => '', // MM/DD/YYYY
'coupon_limit' => false,
'coupon_stackable' => false,
),
)
);