gform_stripe_subscription_params_pre_update_customer

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 ) {
	$feed_name = rgars( $feed, 'meta/feedName' );

	gf_stripe()->log_debug( 'Feed: ' . $feed_name . '; Entry: ' . $entry['id'] );

	// Define the names of the feeds you want to target here.
	$feed_names = array( 'feed name one', 'feed name two' );

	if ( ! in_array( $feed_name, $feed_names ) ) {
		// Abort if the entry was processed by a different feed.
		return;
	}

	// Set your desired cancellation date here.
	$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.