update some user meta when a payment has been made

Im looking for a way to update some user meta when a payment has been made, we are using Stripe.

Can you tell me what the payment callback method is please and how I would implement this.


  • Jude
    • DEV MAN

    Hey @Marc Sniukas

    Hope you are keeping well !

    Here is the filter that you can use with Stripe to help with this task


    Check the $was_paid variable, if its true then you can assume the payment was a success and update the meta.

    Let me know if you need further help with this.


  • Marc Sniukas
    • Site Builder, Child of Zeus

    So 'ms_gateway_stripe_request_payment_after' is this a hook that will trigger after Stripe callback, where should I put this code then?

    function ms_gateway_stripe_request_payment_after($subscription,$was_paid,$this){
    	echo $subscription;
    	echo '##';
    	echo $was_paid;
            // update user meta stuff here

    If so, how do I get the users ID, does the callback fire independently from Stripe server?

  • Michael Bissett
    • Recruit

    Hey @Marc Sniukas,

    We're really talking about custom development territory here, I should note that we do have a policy on that over here:


    Concisely put, the action hook that my colleague Jude had referenced would first need to be called, like this:

    add_action ( 'ms_gateway_stripe_request_payment_after', 'enter-name-of-your-function-here', 10, 2);

    (and of course, you'd replace enter-name-of-your-function-here with the actual name of your function)

    You can learn more about the add_action function over here:


    As to the writing of the function itself, Membership 2 Pro does come with an API, you can check it out inside of the plugin by going to:

    Membership 2 -> Help -> API Docs

    I'd say that you'd want to check out the "MS_Model_Member" & "MS_Model_Relationship" sections, and obtain the information on the member via our API.

    This does sound like something that'd be suited for our Jobs Board, though, you'd be more than welcome to post a job over there, and have one of our Pros cook up a code snippet that does all what you're wanting it to:


    Kind Regards,

  • Marc Sniukas
    • Site Builder, Child of Zeus

    ok so I try this

    add_action ('ms_gateway_stripe_request_payment_after', 'after_payment', 10, 2);
    function after_payment($subscription,$was_paid){
    	$sub = var_dump($subscription, true);
    	$paid = var_dump($was_paid, true);
    	mail('email@gmail.com', 'TEST', $sub.$paid);	

    And I get no email, does it work in Sandbox?

  • Michael Bissett
    • Recruit

    Hey @Marc Sniukas,

    Do you mean to say that you tried out this code in Sandbox mode, or did you mean to ask something else?

    Like I said, building a function like what you're wanting would fall under the realm of our custom development policy, but I can offer some advice in closing:

    You'll want to be checking to see if there's any errors coming up, I'd advise entering the following into your site's wp-config.php:

    // Enable WP_DEBUG mode
    define('WP_DEBUG', true);
    // Enable Debug logging to the /wp-content/debug.log file
    define('WP_DEBUG_LOG', true);
    // Disable display of errors and warnings
    define('WP_DEBUG_DISPLAY', false);

    That way, when you try signing up for a Stripe subscription in the Sandbox, you'll be able to catch any errors that come up. Please note, though, that the hook that my colleague Jude offered is for the Stripe Single Gateway. If you're wanting the one for the Stripe Subscriptions Gateway, you'll need to hook into this one instead:


    Check to see if your function's even being run in the first place, try even sending out a basic email first, using code like this:

    wp_mail( 'me@example.net', 'The subject', 'The message' );

    Just to see if your function's executing in the first place.

    In the end, though, if this is still quite a bit to sort out, I'd advise posting a job for this on our Jobs Board, as mentioned earlier. :slight_smile:

    Kind Regards,

  • Jude
    • DEV MAN

    Hi again @Marc Sniukas

    Can you try with this code instead ?

    add_action ( 'ms_gateway_stripe_request_payment_after', 'update_my_meta', 999, 3);
    function update_my_meta( $sub, $is_paid, $t) {
           mail('email@gmail.com', 'TEST',  "Was Paid : ".$is_paid);
           if( $is_paid )
               update_user_meta( $sub->user_id, 'some_meta', 'some_value' );

    Put your email and the meta values you want updated.

    Hope that helps


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.