Support » Plugin: Payment Button for PayPal » update_user_meta after pay was complet

  • Hey.

    Is there any way i can fire update_user_meta after a pay?
    update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );

    I found in your code:
    add_action('save_post', 'wp_paypal_save_meta_box_data');

    I think best would be if i do it like here:

     if (isset($_POST['_payment_status'])) {
            $payment_status = sanitize_text_field($_POST['_payment_status']);
            update_post_meta($post_id, '_payment_status', $payment_status);
            update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );

    So which is the safest way to put that in my functions.php file?
    I want change user meta when paying is done & complete. So if product is 100% payed 🙂

    Best Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Noor Alam


    Hi, I added a new action hook after the payment is processed by the plugin. You should be able to listen to that hook and do what’s necessary. For example:

    add_action('wp_paypal_order_processed', 'custom_update_user_meta');
    function custom_update_user_meta($post_id) {
        $payment_status = get_post_meta($post_id, '_payment_status', true);
        if(isset($payment_status) && $payment_status=='Completed'){
            update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
    • This reply was modified 5 years, 7 months ago by Noor Alam.

    Hi @naa986,
    first, thanks for your great plugin, but I have a question here,
    if we want to update_user_meta, we need user_id information, but the action ‘wp_paypal_order_processed’ was triggered by the paypal_ipn call, so, we cannot get the current front-end user_id with the get_user_id() function of wordpress since the paypal_ipn have no idea who make the call, I think we may need to add the user_id information to the notify_url, then we can retrive it, and pass it via the ‘wp_paypal_order_processed’ action, would you mind updating your plugin to achieve this feature?

    If you are busing on other project, please let me know, I am happy to update it 🙂

    For someone who want user_id information from IPN call, here is a quick hacking,

    file: wp-content/plugins/wp-paypal/paypal-ipn.php
    before this line(about line 115), wp_paypal_debug_log("Updating order information", true);
    adding following code


    before this line(about line 140), do_action('wp_paypal_order_processed', $post_id);
    adding following code

        update_post_meta($post_id, '_user_id', $user_id);
        do_action('wp_paypal_order_processed_ipn_response', $post_id,$ipn_response,$user_id);

    change this line(about line 296): $atts['callback'] = home_url() . '/?wp_paypal_ipn=1';
    to this:
    $atts['callback'] = home_url() . '/?wp_paypal_ipn=1&user_id='.get_current_user_id();

    after all above changes, you can use following function to hook on the new action and do what you want,

    function c9mf_hook_wp_paypal_order_processed_ipn_response($post_id,$ipn_response,$user_id)
    /* ipn_response sample
    [transaction_subject] => Monthly fee
    [payment_date] => 00:18:30 Oct 22, 2016 PDT
    [txn_type] => subscr_payment
    [subscr_id] => I-UH1FCT2P80M9
    [last_name] => buyer
    [residence_country] => CN
    [item_name] => Monthly fee
    [payment_gross] => 10.00
    [mc_currency] => USD
    [business] =>
    [payment_type] => instant
    [protection_eligibility] => Ineligible
    [verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31At3k7RW3LJrgx7UCuT72hnR3sARy
    [payer_status] => verified
    [test_ipn] => 1
    [payer_email] =>
    [txn_id] => 2G162234UC429330Y
    [receiver_email] =>
    [first_name] => test
    [payer_id] => LQRQ8N8LT4WMG
    [receiver_id] => 8BMVT4A9RKB4W
    [payment_status] => Completed
    [payment_fee] => 0.69
    [mc_fee] => 0.69
    [mc_gross] => 10.00
    [charset] => windows-1252
    [notify_version] => 3.8
    [ipn_track_id] => ea507fe44d737
        $payment_status = get_post_meta($post_id, '_payment_status', true);
        if(isset($payment_status) && $payment_status=='Completed'){
            //do anything here
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘update_user_meta after pay was complet’ is closed to new replies.