• Resolved johngtrs

    (@johngtrs)


    I’m trying to get the current user email when he completed the order. But the user email is empty and he’s not logged.

    Here is my code :

    function mysite_woocommerce_order_status_completed( $order_id ) {
    $order = new WC_Order( $order_id );
    $nb_credit = $order->get_item_count(); // it works
    $current_user = wp_get_current_user(); // This is empty
    }

    add_action( ‘woocommerce_order_status_completed’, ‘mysite_woocommerce_order_status_completed’ );

    How can I get the current user email ?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter johngtrs

    (@johngtrs)

    I found a solution. I get the user id with the WC_Order object and get the email user with it.

    Here his my code :

    $order = new WC_Order( $order_id ); // WC_Order object
    
        $user_id = $order->get_user_id();     // get the user id
        $user = get_user_by('id', $user_id );  // get the user by id field
    
        $current_email = $user->user_email;   // user mail
    Thread Starter johngtrs

    (@johngtrs)

    Forgot to mark this topic as resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce Paypal get current user inside order status completed’ is closed to new replies.