bookmark_bordergform_stripe_customer_id

Description

The gform_stripe_customer_id filter can be used to specify an existing customer ID to be used when processing the submission.

Usage

The hook which would run for all Stripe feeds can be used like so:

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

Parameters

  • $customer_id string

    The Stripe customer id. Defaults to an empty string causing a new customer to be created when processing the subscription feed.

  • $feed Feed Object

    The Feed which is currently being processed.

  • $entry Entry Object

    The Entry which is currently being processed.

  • $form

    The Form which is currently being processed.

Examples

1. ID from user meta

The following example shows how, if the user is logged in, you can retrieve the customer id from the user meta. See the gform_stripe_customer_after_create hook for an example showing how the customer id can be saved to the user meta.

add_filter( 'gform_stripe_customer_id', 'get_stripe_customer_id' );
function get_stripe_customer_id( $customer_id ) {
	if ( is_user_logged_in () ) {
		$customer_id = get_user_meta( get_current_user_id(), '_stripe_customer_id', true );
	}

	return $customer_id;
}

Placement

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

Source Code

$customer_id = apply_filters( 'gform_stripe_customer_id', $customer_id, $feed, $entry, $form );

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

Since

This hook was added in Stripe version 2.1