Description
The gform_coupons_update_usage_count filter allows custom logic to determine whether a coupon’s usage count should be updated.
Usage
add_filter( 'gform_coupons_update_usage_count', 'your_function_name', 10, 5 );
To target a specific form, append the form ID to the hook name. (format: gform_coupons_update_usage_count_FORMID)
add_filter( 'gform_coupons_update_usage_count_10', 'your_function_name', 10, 5 );
Parameters
| Parameter | Type | Description |
|---|---|---|
$update_usage_count | bool | Whether the usage count should be updated. Default is true. |
$coupon_code | string | The coupon code. |
$entry | Entry Object | The entry currently being processed. |
$form | Form Object | The form currently being processed. |
$feed | Feed Object | The coupon feed currently being processed. |
Examples
Only Update Usage Count When Payment Is Completed.
This example ensures the coupon usage count is only updated when the entry has a completed payment status.
add_filter( 'gform_coupons_update_usage_count', function( $update_usage_count, $coupon_code, $entry, $form, $feed ) {
$is_paid = $entry['payment_status'] === 'Paid' || $entry['payment_status'] === 'Active';
return $is_paid;
}, 10, 5 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
$update_usage_count = gf_apply_filters( array( 'gform_coupons_update_usage_count', $form['id'] ), true, $coupon_code, $entry, $form, $feed );
This filter is located in GFCoupons::update_usage_count() in class-gf-coupons.php.
Since
This filter was added in the Coupons Add-On 3.6.0