GFCoupons

Overview

GFCoupons is the class which houses the main functionality of the Gravity Forms Coupons Add-on, it extends the GFFeedAddOn class which is part of the add-on framework. Below are a few functions which you may find useful when working on your own custom code.

gf_coupons()

The gf_coupons() function is used to return an instance of the GFCoupons class.

$coupons = gf_coupons();

get_submitted_coupon_codes()

Retrieves any submitted coupon codes from the entry object.

$coupon_codes = gf_coupons()->get_submitted_coupon_codes( $form, $entry );
ParameterTypeDescription
$formForm ObjectThe form object currently being processed.
$entryEntry ObjectThe entry object currently being processed.

Returns array | boolean. An array of coupon codes or false if no codes were submitted.

get_coupons_by_codes()

Retrieves the properties for the specified coupon codes.

$coupons = gf_coupons()->get_coupons_by_codes( $codes, $form );
ParameterTypeDescription
$codesstring | arrayThe codes for the coupons to be retrieved.
$formForm ObjectThe form object currently being processed.

Returns array | boolean. An associative array with the coupon code as key to the array containing that coupons properties. False if no coupon feeds were found.

insert_feed()

The insert_feed() method can be used to add new coupons.

$feed_id = gf_coupons()->insert_feed( $form_id, $is_active, $meta );
ParameterTypeDescription
$form_idintegerThe ID of the form this coupon can be used with or 0 if it can be used with all forms.
$is_activebooleanIs this coupon active or inactive.
$metaCoupons Feed MetaAn associative array containing the properties which determine the type of coupon and discount available.

Returns integer. The ID of the new feed.