Created
May 10, 2021 15:30
-
-
Save dparker1005/e74ee12f0dc59c57bb56b19ef458a9c7 to your computer and use it in GitHub Desktop.
Send user ID to Stripe as metadata.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Copy from below here... | |
/** | |
* Send user ID to Stripe as metadata. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_stripe_params_send_user_id( $params, $order = null ) { | |
global $my_pmpro_checkout_order; | |
if ( empty( $params['metadata'] ) ) { | |
$params['metadata'] = array(); | |
} | |
if ( empty ( $order ) ) { | |
// Save order while creating payment intent. | |
$order = $my_pmpro_checkout_order; | |
} else { | |
// Use saved order while creating subscription. | |
$my_pmpro_checkout_order = $order; | |
} | |
$params['metadata']['wp_user_id'] = $order->user_id; | |
return $params; | |
} | |
add_filter( 'pmpro_stripe_payment_intent_params', 'my_pmpro_stripe_params_send_user_id', 10, 2 ); | |
add_filter( 'pmpro_stripe_create_subscription_array', 'my_pmpro_stripe_params_send_user_id', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment