gform_stripe_charge_description

Description

This filter can be used to modify the charge description for Products and Services feeds before it is sent to Stripe.

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.

For Subscription transactions, please see the gform_submission_data_pre_process_payment filter.

You may also want to check gform_stripe_charge_pre_create to add the statement_descriptor property used on bank statements.

Usage

The filter, which would run for all ‘product and services’ type Stripe feeds, can be used like so:

add_filter( 'gform_stripe_charge_description', 'your_function_name', 10, 5 );

Parameters

  • $description string

    The description to be modified.

    $description = 'Entry ID: 123, Products: Product A, Product B, Product C';
  • $strings array

    Contains the Entry ID and Products. This is the array which was imploded to create the description string.

        $strings = array(
            'entry_id' => 'Entry ID: 123',
            'products' => 'Products: Product A, Product B, Product C',
        );
        
  • $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.

Examples

1. Remove the entry ID

The following 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 );
}

2. Include a field value

The following 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' );
}

3. Override the default description completely

The following example shows how you can replace the default description with a 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 ) {
	GFCommon::log_debug( __METHOD__ . '(): running.' );
	$feed_name  = rgars( $feed, 'meta/feedName' );

	// Update the following line to use your feed name.
	if ( 'Invoice Payment via Stripe' != $feed_name ){
		return $description;
	}

	GFCommon::log_debug( __METHOD__ . '(): running for feed ' . $feed_name );

	// Change 21 to your field id number.
	$description = 'Invoice Payment for #' . rgar( $entry, '21' );

	GFCommon::log_debug( __METHOD__ . '(): Custom Description: ' . $description );
	return $description;
}

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

apply_filters( 'gform_stripe_charge_description', implode( ', ', $strings ), $strings, $entry, $submission_data, $feed )

This filter is located in GFStripe::get_payment_description() in class-gf-stripe.php.