gform_stripe_charge_description

gform_stripe_charge_description

DescriptionUsageParametersExamples1. Remove the entry ID2. Include a field value3. Override the default description completelyPlacementSource Code

Description

This filter can be used to modify the charge description before it is sent to Stripe.

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 you can 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

Your code snippet should be placed in the functions.php file of your active theme.

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.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注