Home / Admin / WP Simple Pay: Programmatically Access Payment Metadata After Payment
Duplicate Snippet

Embed Snippet on Your Site

WP Simple Pay: Programmatically Access Payment Metadata After Payment

Programmatically access metadata (such as custom field values) associated with a payment record after a subscription is created or one-time payment is successful.

Code Preview
php
<?php
/**
 * @link https://library.wpcode.com/snippet/3234p8or/
 * 
 * @param StripeEvent $event Stripe Event.
 * @param StripeSubscription|StripePaymentIntent $object Stripe Subscription or PaymentIntent
 */
function simpay_custom_create_user( $event, $object ) {
	$metadata = $object->metadata->toArray();
	
	// Access a custom field with a "Stripe Metadata Label" of "Color":
	$color = isset( $metadata['Color'] ) ? esc_html( $metadata['Color'] ) : '-';
	
	// Do something with the value of $color...
}
add_action( 'simpay_webhook_subscription_created', 'simpay_custom_create_user', 10, 2 );
add_action( 'simpay_webhook_payment_intent_succeeded', 'simpay_custom_create_user', 10, 2 );

Comments

Add a Comment