How To Send Metadata to Stripe Payments


Would you like to send through metadata to Stripe when payments are processed through your form? If you’d like to add some tags that you can easily identify in your Stripe payments, you can send metadata as part of the payment through WPForms. In this tutorial, we’ll show you the PHP snippet you need in order to achieve this.


First, you’ll need to add the Credit Card form field and set up your form to accept Stripe payments.

Add the credit card field to your form

If you need assistance in setting up Stripe on your form, please review this documentation.

Next, copy and paste this code snippet to your site.

 * Send metadata to Stripe when payment is processed.
 * @link

function wpf_stripe_single_payment_custom_metadata( $fields, $form_data, $entry_id, $payment ) {
	if ( ! ( $payment instanceof \Stripe\PaymentIntent ) && ! ( $payment instanceof \Stripe\Charge ) ) {
	// Check if the field with id equals 16 value exists and assign it.
	if ( isset( $fields[16]['value'] ) ) {
		$payment->metadata['something'] = $fields[16]['value'];
	// Assign fixed value (no additional checks required).
	$payment->metadata['key'] = 'some value for single payment';
add_action( 'wpforms_stripe_process_complete', 'wpf_stripe_single_payment_custom_metadata', 10, 4 );

In the above code snippet, we’re sending through two forms of metadata. One is assigned from a specific form field with $fields[16]['value']. And the other is specific with the metadata['key'] = 'some value for single payment';.

You’ll just need to remember to change each of those for what you need.

You now now see the metadata sent to Stripe when the payment is processed

And that’s it! You’ve successfully sent metadata to Stripe. Would you like to change the sublabels on the Credit Card field? Take a look at our article on How to Change Sublabels for the Credit Card Field.

Action Reference: wpforms_stripe_process_complete


Q: Will this work for recurring and single payments?

A: Absolutely! The code above will work for both single payments as well as the initial subscription payment (not the subscription itself).