Support » Plugin: User Switching » Recording the admin user on woocommerce orders?

  • Resolved the_lar

    (@the_lar)


    Hi,

    I’m using the user-switching plugin to let salespeople to switch to customer accounts in woocommerce and place orders – this works really well but I also need to be able to record who took the order at the point where the order is created. This is so that the company can see which salespeople are effective etc and it will need to be sent to their CRM.

    Question is how to obtain this information and assign it to some meta on the woocommerce order?

    Many thanks
    Kevin

Viewing 1 replies (of 1 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the question!

    User Switching stores the old user ID in the switched_from_id property of the user session when they switch. You can access it like this:

    $token   = wp_get_session_token();
    $manager = WP_Session_Tokens::get_instance( get_current_user_id() );
    $session = $manager->get( $token );
    
    var_dump( $session['switched_from_id'] ?? 0 );

    The old user’s original session ID is also stored in the switched_from_session property, should you need it.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.