grabbing this info programatically

So, I am looking to grab some info from users programatically.
For example on Membership Pro and Pro Sites I would like to get this info:
revenue: <?php echo $order_total; ?>, (i.e. or its equal for M2P and Pro Sites)
reference: '<?php echo $order_number; ?>' (i.e. or invoice number, or its equal for M2P and Pro Sites etc)
and
label: '<?php echo $user['username']; ?>',
name: '<?php echo $user['full_name']; ?>',
email: '<?php echo $user['email']; ?>'

1st for Membership Pro and Pro Sites what is the correct replacement for the top two?
and 2nd the last 3 is universal for PHP right and should return those values correctly?

:slight_smile:

Greg

  • James Morris

    Hello Greg

    I hope you are well today.

    This is a bit more of a advanced query and a custom code request. I'm afraid I'll need to ping our SLS Team to get their valuable feedback on this. Please keep in mind that they have to reply to their queue in order as well, so there may be a little delay in response. Thank you for your patience while our team looks into this.

    Best regards,

    James Morris

  • James Morris

    Hello Greg

    I'm terribly sorry, but there has not been an update on this issue just yet. Our SLS Team handles the advanced issues and many of the bug reports. So, at times, there queue can get rather large. Generally, they do their best to reply within 72hrs, but much will depend on the length of their queue. An update will be posted here as soon as more information is available. Thank you for your patience.

    Best regards,

    James Morris

  • Panos

    Hi Greg ,

    What you first need is to specify what is the information you have and at what action in order to get the user id.

    As you mention order id I assume it is after payment. It would be better to know the gateways you are using but I think for Membership the following would work:

    add_action( 'ms_invoice_paid', function( $invoice, $subscription ){
    
    	$member	= $invoice->get_member();
    	$user_id = $member->id;
    	$user_name = $member->name;
    	$first_name = $member->first_name;
    	$last_name = $member->last_name;
    	$emain = $member->email;
    
    }, 20, 2 );

    For ProSites could you specify the payment gateway you are using?

    Could you also provide clear information about the action that you need these for each plugin in case I have been missing something?

    Thanks!

  • Panos

    Hi Greg ,

    Your requirements are for custom development and we can't provide working solutions, however when possible we love to provide some advise or snippets to be used as a guide.

    I still don't have a clear picture of what you need to accomplish. Hopefully the following samples would help you on what you need.

    Regarding Membership plugin, the above snippet (provided in my previous reply) should work. Each time an invoice is paid you can get the user information with the snippet above. Alternatively to target specifically Stripe you can use the following for Single and Recurring payments accordingly :

    //Stripe Single
    add_filter( 'ms_gateway_stripe_process_purchase', function( $invoice ){
    
    	$member = $invoice->get_member();
    	$user_id = $member->id;
    	$user_name = $member->name;
    	$first_name = $member->first_name;
    	$last_name = $member->last_name;
    	$email = $member->email;
    
    	return $invoice;
    }, 20 );
    
    //Stripe Recurring
    add_filter( 'ms_gateway_stripeplan_process_purchase', function( $invoice ){
    
    	$member = $invoice->get_member();
    	$user_id = $member->id;
    	$user_name = $member->name;
    	$first_name = $member->first_name;
    	$last_name = $member->last_name;
    	$email = $member->email;
    
    	return $invoice;
    }, 20 );

    As for ProSites it does not provide any hook for successful payments, but we can use the webhook used from Stripe. Here is an example:

    function ps_stripe_webhook_handler() {
    
        $body = @file_get_contents( 'php://input' );
        $event_json = json_decode( $body );
    
        $event_type = $event_json->type;
    
        if ( 'invoice.payment_succeeded' == $event_type ) {
    
            $customer_id = '';
            if ( ! empty( $event_json->data->object->object ) && 'customer' == $event_json->data->object->object ) {
                $customer_id = $event_json->data->object->id;
            } elseif ( ! empty( $event_json->data->object->customer ) ) {
                $customer_id = $event_json->data->object->customer;
            }
    
            if ( empty( $customer_id ) ) {
                return;
            }
    
            $blog_id = ProSites_Gateway_Stripe::get_blog_id( $customer_id );
    
            switch_to_blog( $blog_id );
            $admin_email = get_option( 'admin_email' );
            restore_current_blog();
    
            $user = get_user_by( 'email', $admin_email );
    
            if( ! $user instanceof WP_User ){
            	return;
            }
    
            $user_info = get_userdata( $user->ID );
    
            $username = $user_info->user_login;
            $first_name = $user_info->first_name;
            $last_name = $user_info->last_name;
    
        }
    
    }
    
    add_action( 'wp_ajax_nopriv_psts_stripe_webhook', 'ps_stripe_webhook_handler' );
    add_action( 'wp_ajax_psts_stripe_webhook', 'ps_stripe_webhook_handler' );

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.