Skip to content

Instantly share code, notes, and snippets.

@zainaali
Created October 21, 2020 11:26
Show Gist options
  • Save zainaali/98deb748bf4f0c4a21d142e01ba10658 to your computer and use it in GitHub Desktop.
Save zainaali/98deb748bf4f0c4a21d142e01ba10658 to your computer and use it in GitHub Desktop.
Create a Stripe Customer with Gravity Forms Stripe Product Feed
add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'Create Customer and Payment' ) {
$customer_meta = array();
$metadata_field = rgars( $feed, 'meta/metaData' );
foreach ($metadata_field as $metadata) {
if ($metadata['custom_key'] == 'Email') {
$email_field = $metadata['value'];
}
}
if ( ! empty( $email_field ) ) {
$customer_meta['email'] = gf_stripe()->get_field_value( $form, $entry, $email_field );
}
$customer = gf_stripe()->create_customer( $customer_meta, $feed, $entry, $form );
return $customer->id;
}
return $customer_id;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment