gform_submit_button

gform_submit_button

DescriptionUsageParametersExamples1. Change input to button2. Add text after the button3. Remove the button4. Append a JavaScript action to the button5. Append custom CSS classes to the buttonPlacementSource Code

Description
This filter is executed when the form is displayed and can be used to completely change the form button tag (i.e. ).
Usage
The following would apply your function to all forms.
add_filter( 'gform_submit_button', 'your_function_name', 10, 2 );

To target a specific form append the form id to the hook name. (format: gform_submit_button_FORMID)
add_filter( 'gform_submit_button_5', 'your_function_name', 10, 2 );

Parameters

$button_input string
The string containing the tag to be filtered.

$form Form Object
The form currently being processed.

Examples
1. Change input to button
This example changes the default input type to use the button element with an included span, popular for implementing the Sliding Door CSS technique.
add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
return "";
}

Note: The above is just a quick example showing how to use the filter. Using the above code will prevent the form submitting as the onclick attribute is missing.
Here』s another example which would change all the next, previous, and submit buttons so they use button elements from a single function while maintaining attributes such as onclick from original inputs.
/**
* Filters the next, previous and submit buttons.
* Replaces the forms buttons with

gform_submission_values_pre_save

gform_submission_values_pre_save

DescriptionUsageParametersExampleSource Code

Description
Allows the modification of submitted values before the incomplete submission is saved.
Usage
1add_filter( 'gform_submission_values_pre_save', 'my_function_call' );

Parameters

$submitted_values array
The submitted values.

$form array
The Form Object.

Example
123456add_filter( 'gform_submission_values_pre_save', 'submission_values_pre_save', 10, 2 ); function submission_values_pre_save( $submitted_values, $form ) {  $submitted_values['custom_value'] = $_POST['custom_value'];  return $submitted_values;}
Source Code
This filter is located in forms_model.php

gform_submission_data_pre_process_payment

gform_submission_data_pre_process_payment

DescriptionUsageParametersExamples1. Change the Payment Amount2. Set the Number of Trial Days3. Set the Authorize.Net Line Item Taxable Status4. Customize the name for a Line ItemPlacementSource CodeSince

Description

This filter can be used to modify the Submission Data before it』s used during feed processing by a payment add-on based on the Add-On Framework.

Usage

The base filter which would run for all forms with a payment add-on feed would be used like so:

add_filter( 'gform_submission_data_pre_process_payment', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_submission_data_pre_process_payment_FORMID)

add_filter( 'gform_submission_data_pre_process_payment_10', 'your_function_name', 10, 4 );

Parameters

$submission_data Submission Data Object
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 currently being processed.

$form Form Object
The form currently being processed.

$entry Entry Object
The entry currently being processed.

Examples

1. Change the Payment Amount

This example shows how you can override the payment_amount for form 10 with the value from field 5.

add_filter( 'gform_submission_data_pre_process_payment_10', 'modify_submission_data', 10, 4 );
function modify_submission_data( $submission_data, $feed, $form, $entry ) {
$submission_data['payment_amount'] = rgar( $entry, '5' );

return $submission_data;
}

2. Set the Number of Trial Days

This example shows how you can override the trial property (i.e. the number of trial days) for form 5.

add_filter( 'gform_submission_data_pre_process_payment_5', 'modify_submission_data', 10, 4 );
function modify_submission_data( $submission_data, $feed, $form, $entry ) {

if ( $feed['meta']['feedName'] != 'feed name goes here' ) { // Update this line to your feed name
return;
}

$submission_data['trial'] = 15;

return $submission_data;
}

3. Set the Authorize.Net Line Item Taxable Status

This example shows how you can override the default taxable status of Y to N for the line items of form 3. This is supported as of Authorize.Net version 2.2.1.

add_filter( 'gform_submission_data_pre_process_payment_3', 'override_line_item_tabaxable', 10, 4 );
function override_line_item_tabaxable( $submission_data, $feed, $form, $entry ) {
foreach ( $submission_data['line_items'] as &$line_item ) {
$line_item['taxable'] = 'N';
}

return $submission_data;
}

4. Customize the name for a Line Item

This example shows how you can override the name of a line item, from the default (product label 「My Product」) to a custom name.

add_filter( 'gform_submission_data_pre_process_payment', 'gf_custom_lite_item_name', 10, 4 );
function gf_custom_lite_item_name( $submission_data, $feed, $form, $entry ) {
foreach ( $submission_data['line_items'] as &$line_item ) {
GFCommon::log_debug( __METHOD__ . '(): Line Item Name => ' . $line_item['name'] );
if ( $line_item['name'] == 'My Product' ){
$line_item['name'] = 'Custom Name Text Here';
}
}
GFCommon::log_debug( __METHOD__ . '(): Modified Submission Data => ' . print_r( $submission_data, true ) );
return $submission_data;
}

Placement

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

Source Code

gf_apply_filters( 'gform_submission_data_pre_process_payment', $form['id'], $submission_data, $feed, $form, $entry );

This filter is located in GFPaymentAddOn::get_submission_data() in includes/addon/class-gf-payment-addon.php.

Since

This filter was added in Gravity Forms 1.9.12.8.

gform_stripe_webhook

gform_stripe_webhook

DescriptionUsageParametersExamples1. Add a new event typePlacementSinceSource Code

Description
The gform_stripe_webhook filter can be used to add support for performing actions on additional Stripe events. The following event types are supported by default:

charge.expired
charge.refunded
charge.captured (only for Stripe Checkout)
customer.subscription.deleted
invoice.payment_succeeded
invoice.payment_failed
checkout.session.completed

See the Stripe API Reference for a full list of event types for which webhooks are sent.
Usage
The hook which would run for all Stripe feeds can be used like so:
add_filter( 'gform_stripe_webhook', 'your_function_name', 10, 2 );

Parameters

$action array
An associative array containing the event details or an empty array for unsupported event types.
$action = array(
'type' => '',
'amount' => '',
'transaction_type' => '',
'transaction_id' => '',
'subscription_id' => '',
'entry_id' => '',
'payment_status' => '',
'note' => '',
);

$event StripeEvent
The Stripe event object for the webhook which was received.

Examples
1. Add a new event type
The following shows how you can add support for processing webhooks for other event types than the defaults listed above.
add_filter( 'gform_stripe_webhook', 'stripe_webhook_custom_action', 10, 2 );
function stripe_webhook_custom_action( $action, $event ) {
$type = rgar( $event, 'type' );

switch ( $type ) {
case 'charge.failed':

$action['transaction_id'] = rgars( $event, 'data/object/id' );
$entry_id = gf_stripe()->get_entry_by_transaction_id( $action['transaction_id'] );
if ( ! $entry_id ) {
return new WP_Error( 'entry_not_found', sprintf( 'Entry for transaction id: %s was not found. Webhook cannot be processed.', $action['transaction_id'] ) );
}

$entry = GFAPI::get_entry( $entry_id );

$action['entry_id'] = $entry_id;
$action['type'] = 'fail_payment';
$action['amount'] = gf_stripe()->get_amount_import( rgars( $event, 'data/object/amount' ), $entry['currency'] );

break;
}

return $action;
}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe v1.0.
Source Code
$action = apply_filters( 'gform_stripe_webhook', $action, $event );

This hook is located in GFStripe::callback() in class-gf-stripe.php.

gform_stripe_webhook_signing_secret

gform_stripe_webhook_signing_secret

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
The 「gform_stripe_webhook_signing_secret」 filter in the Gravity Forms Stripe Add-On allows the webhook signing secret for the specified API mode to be modified.
Usage
add_filter( 'gform_stripe_webhook_signing_secret', 'your_function_name', 10, 3 );

Parameters

$signing_secret string
The signing secret to be used when validating received webhooks.

$mode string
The API mode; live or test.

$gfstripe object
GFStripe class object.

Examples
add_filter( 'gform_stripe_webhook_signing_secret', 'change_secret', 10, 3 );
function change_secret( $signing_secret, $mode, $gfstripe ){
if ( $mode == 'test' ){
return '1234567890';
}
else {
return '222222222';
}
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe v2.3.1.
Source Code
This filter is located in GFStripe::get_webhook_signing_secret() in gravityformsstripe/class-gf-stripe.php.

gform_stripe_url_port

gform_stripe_url_port

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Set the Stripe URL port if it』s not 80.
Usage
$server_port = apply_filters( 'gform_stripe_url_port', $_SERVER['SERVER_PORT'] );

Parameters

$server_port string
Default server port.

Example
$server_port = apply_filters( 'gform_stripe_url_port', $_SERVER['SERVER_PORT'] );

if ( $server_port != '80' ) {
$page_url .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI'];
} else {
$page_url .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe 3.0.
Source Code
This filter is located in class-gf-stripe.php.

gform_stripe_success_url

gform_stripe_success_url

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Filters Stripe session』s success URL, which is the URL that users will be sent to after completing the payment on Stripe.
Usage
add_filter( 'gform_stripe_success_url', function ($url, $form_id, $query ) {
// Your code here.
}, 10, 3 );

Parameters

$url string
The URL to be filtered.

$form_id int
The ID of the form being submitted.

$query string
The query string portion of the URL.

Example
The following example will change the URL to use a domain of your choice if for any reason the site is provide localhost as domain.
add_filter( 'gform_stripe_success_url', function ($url, $form_id, $query ) {
GFCommon::log_debug( __METHOD__ . '(): Original URL: ' . $url );
// Replace example.com with your site domain.
$url = str_replace( 'localhost', 'example.com', $url );
GFCommon::log_debug( __METHOD__ . '(): New URL: ' . $url );
return $url;
}, 10, 3 );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe 3.0.
Source Code
This filter is located in class-gf-stripe.php.

gform_stripe_subscription_params_pre_update_customer

gform_stripe_subscription_params_pre_update_customer

DescriptionUsageParametersExamplesCancel at period endCancel at specified date/timePlacementSinceSource Code

Description
The 「gform_stripe_subscription_params_pre_update_customer」 filter in the Gravity Forms Stripe Add-On allows the subscription parameters to be overridden before the customer is subscribed to the plan.
Usage
add_filter( 'gform_stripe_subscription_params_pre_update_customer', 'your_function_name', 10, 7 );

Parameters

$subscription_params array
The subscription parameters. Check out Stripe』s documentation to see what parameters subscriptions can accept.

$customer object
The Stripe customer object.

$plan object
The Stripe plan object.

$feed Feed Object
The feed currently being processed.

$entry Entry Object
The entry currently being processed.

$form Form Object
The form which created the current entry.

$trial_period_days int
The number of days the trial should last.

Examples
Cancel at period end
The example below sets the subscription to be cancelled at the end of the current period.
add_filter( 'gform_stripe_subscription_params_pre_update_customer', 'change_details', 10, 7 );
function change_details( $subscription_params, $customer, $plan, $feed, $entry, $form, $trial_period_days ) {
$subscription_params['cancel_at_period_end'] = true;

return $subscription_params;
}

Cancel at specified date/time
This example shows how you can provide a timestamp at which the subscription should cancel.
add_filter( 'gform_stripe_subscription_params_pre_update_customer', 'stripe_subscription_cancel_at', 10, 7 );
function stripe_subscription_cancel_at( $subscription_params, $customer, $plan, $feed, $entry, $form, $trial_period_days ) {
$subscription_params['cancel_at'] = strtotime( '2020-12-31' );

return $subscription_params;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe version 2.3.4.
Source Code
This filter is located in GFStripe::update_subscription() in gravityformsstripe/class-gf-stripe.php.

gform_stripe_subscription_cancel_at_period_end

gform_stripe_subscription_cancel_at_period_end

DescriptionUsageParametersExamples1. Apply to all subscriptions2. Apply to a specific feedPlacementSinceSource Code

Description
The gform_stripe_subscription_cancel_at_period_end filter can be used to delay the cancellation of the subscription until the end of the current period.
Usage
The hook which would run for all Stripe feeds can be used like so:
add_filter( 'gform_stripe_subscription_cancel_at_period_end', 'your_function_name', 10, 3 );

Parameters

$at_period_end bool
Defaults to false, subscription will be cancelled immediately.

$entry Entry Object
The entry from which the subscription was created.

$feed Feed Object
The feed object which processed the current entry.

Examples
1. Apply to all subscriptions
add_filter( 'gform_stripe_subscription_cancel_at_period_end', '__return_true' );

2. Apply to a specific feed
The following example shows how you can delay the subscription cancellation for a specific feed by checking the feed name.
add_filter( 'gform_stripe_subscription_cancel_at_period_end', 'stripe_subscription_cancel_at_period_end', 10, 3 );
function stripe_subscription_cancel_at_period_end( $at_period_end, $entry, $feed ) {
$feed_name = rgars( $feed, 'meta/feedName' );
if ( $feed_name == 'your feed name here' ) {
return true;
}

return $at_period_end;
}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This hook was added in Stripe version 2.1.
Source Code
$params['at_period_end'] = apply_filters( 'gform_stripe_subscription_cancel_at_period_end', false, $entry, $feed );

This hook is located in GFStripe::cancel() in class-gf-stripe.php.

gform_stripe_session_data

gform_stripe_session_data

DescriptionUsageParametersExample1. Show product images on the checkout page with the Image Choices add-on2. Add the statement_descriptor property3. Add additional payment method types4. Send metadata before the entry is saved5. Save payment method for future usagePlacementSinceSource Code

Description

Used to set/update product/subscription data before creating the Stripe Checkout session in Stripe. Can be used to add product images.

Usage

$session_data = apply_filters( 'gform_stripe_session_data', $session_data, $feed, $submission_data, $form, $entry );

Parameters

$session_data _autolink_array
Session data for creating the session. See the Stripe documentation for supported arguments.

$feed _autolink_array
The feed object currently being processed.

$submission_data _autolink_array
The customer and transaction data.

$form _autolink_array
The form object currently being processed.

$entry _autolink_array
The entry object currently being processed.

Example

1. Show product images on the checkout page with the Image Choices add-on

The following snippet shows how to add product images to the Stripe Checkout page when using the Gravity Forms Image Choices add-on.

function my_gform_stripe_session_data( $session_data, $feed, $submission_data, $form, $entry ) {
if ( $form['id'] === 4 ) { // set your form id.
foreach ( $submission_data['line_items'] as $k => $line_item ) {
$field = GFAPI::get_field( $form, $line_item['id'] );
if ( rgar( $field, 'choices' ) ) {
$image = gf_image_choices()->get_choice_image_src( $field, $line_item['name'] );
if ( $image ) {
$session_data['line_items'][ $k ]['images'][] = $image;
}
}
}
}

return $session_data;
}
add_filter( 'gform_stripe_session_data', 'my_gform_stripe_session_data', 10, 5 );

2. Add the statement_descriptor property

The following snippet shows how to replace the gform_stripe_charge_pre_create filter for use with the new Stripe Checkout in Stripe add-on version 3.0 and newer.

function my_gform_stripe_session_data( $session_data, $feed, $submission_data, $form, $entry ) {
if ( $form['id'] === 4 ) { // set your form id.
$session_data['payment_intent_data']['statement_descriptor'] = 'STATEMENTDESC';
}
return $session_data;
}
add_filter( 'gform_stripe_session_data', 'my_gform_stripe_session_data', 10, 5 );

To see what charge meta can be replaced with payment_intent_data in the Stripe checkout session, see the Stripe documentation.

3. Add additional payment method types

add_filter( 'gform_stripe_session_data', function( $session_data, $feed, $submission_data, $form, $entry ) {
if ( $form['id'] === 4 ) { // set your form id.
$session_data['payment_method_types'][] = 'ideal';
}

return $session_data;
}, 10, 5 );

See the Stripe API documentation for the supported payment method types and the conditions which must be met for them to be used.

4. Send metadata before the entry is saved

Note: This request is sent during form validation when entry properties such as the id are not available. Also, other field values could be changed after this data has been sent to Stripe.

add_filter( 'gform_stripe_session_data', function ( $session_data, $feed, $submission_data, $form, $entry ) {
if ( ! empty( $session_data['payment_intent_data'] ) && $form['id'] === 4 ) { // set your form id.
$metadata = gf_stripe()->get_stripe_meta_data( $feed, $entry, $form );
if ( ! empty( $metadata ) ) {
// Add metadata to payment intent.
$session_data['payment_intent_data']['metadata'] = $metadata;
}
}

return $session_data;
}, 10, 5 );

5. Save payment method for future usage

The following snippet adds the setup_future_usage parameter to attach the payment method to the customer created at Stripe.com

add_filter( 'gform_stripe_session_data', function( $session_data, $feed, $submission_data, $form, $entry ) {
$session_data['payment_intent_data']['setup_future_usage'] = 'off_session';
return $session_data;
}, 10, 5 );

Placement

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

Since

This filter was added in Stripe 3.0.

Source Code

This filter is located in class-gf-stripe.php.