• Resolved g4macgregor

    (@g4macgregor)


    We have built a function that uses the woocommerce_shop_order_search_results hook to search for something in a custom table that then returns the customer_id, get the WP_User object for that id and are attempting to use javascript confirm() to call maybe_swith_user but are getting the ‘Could not switch users’ response. We’re thinking it is because it’s rebuilding the DOM and we don’t have the necessary info for old_user, but aren’t sure.

    if ( method_exists( 'user_switching', 'maybe_switch_url' ) ) {
         $url = user_switching::maybe_switch_url( $target_user );
         if ( $url ) {
             echo "<script>if ( confirm('This is a historical Opencart serial number. Click OK to jump to his customer') ) document.location='$url';</script>";
         }
    }

    Is there a way you can think of to make this work?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter g4macgregor

    (@g4macgregor)

    Additional information:

    When we write log from the plugin script, we’re seeing:

    
    

    [16-Jun-2022 20:06:44 UTC] Array
    (
    [action] => switch_to_user
    [amp;user_id] => 78091
    [amp;nr] => 1
    [amp;_wpnonce] => c4cbd18580
    )`

    Not sure why it’s prefacing the amp;

    • This reply was modified 3 years, 11 months ago by g4macgregor.
    • This reply was modified 3 years, 11 months ago by g4macgregor.
    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    I’m not sure what could be the problem but you probably should reduce your code down as much as you can to eliminate potential problems. For example replace the JavaScript with a regular <a href="..."> that you output with PHP and then test that it works ok when you click it.

    Thread Starter g4macgregor

    (@g4macgregor)

    Found it, thanks! We needed to html_entity_decode($url)

    • This reply was modified 3 years, 11 months ago by g4macgregor.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Calling the maybe_switch_user function’ is closed to new replies.