The gform_stripe_charge_description filter allows you to modify the charge description before it is sent to Stripe.
Usage
Here’s a generic example of using the filter:
add_filter('gform_stripe_charge_description', 'your_function_name', 10, 5);
Parameters
- $description (string): The description to be modified.
- $strings (array): Contains the Entry ID and Products. This is the array which was imploded to create the description string.
- $entry (Entry Object): The Entry which is currently being processed.
- $submission_data (Submission Data): Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons.
- $feed (Feed Object): The Feed which is currently being processed. Available from v1.7.
More information
See Gravity Forms Docs: gform_stripe_charge_description
Note: Stripe sets a limit of 22 characters for the charge description. If your custom description exceeds that limit, Stripe will replace it with a generic description.
Examples
Remove the entry ID
This example shows how to remove the entry ID from the description.
add_filter('gform_stripe_charge_description', 'remove_entry_id', 10, 2); function remove_entry_id($description, $strings) { unset($strings['entry_id']); return implode(', ', $strings); }
Include a field value
This example shows how you can append the value of a form field to the description.
add_filter('gform_stripe_charge_description', 'append_field_value', 10, 3); function append_field_value($description, $strings, $entry) { return $description . ', Name: ' . rgar($entry, '1.3') . ' ' . rgar($entry, '1.6'); }
Override the default description completely
This example shows how you can replace the default description with custom text and the value of a form field (id 21). The scope of this snippet is limited to a feed with the name ‘Invoice Payment via Stripe’.
add_filter('gform_stripe_charge_description', 'gf_replace_charge_description', 10, 5); function gf_replace_charge_description($description, $strings, $entry, $submission_data, $feed) { $feed_name = rgars($feed, 'meta/feedName'); // Update the following line to use your feed name. if ('Invoice Payment via Stripe' != $feed_name){ return $description; } // Replace the default description with custom text and the value of a form field (id 21). $custom_description = 'Invoice Payment: ' . rgar($entry, '21'); return $custom_description; }
Truncate description to fit Stripe’s limit
This example shows how to truncate the description to fit Stripe’s 22-character limit.
add_filter('gform_stripe_charge_description', 'truncate_description', 10, 1); function truncate_description($description) { return substr($description, 0, 22); }
Customize description based on form ID
This example shows how to customize the description based on the form ID.
add_filter('gform_stripe_charge_description', 'customize_description_based_on_form', 10, 3); function customize_description_based_on_form($description