Support » Plugin: WooCommerce » caching issue when switching to user’s account

  • Resolved Laurendo

    (@laurendo)


    Is woocommerce maintaining the user switching plugin?

    The plugin is having some incompatibility problems with the latest version of Woocommerce.

    2 issues:
    1. It takes a longer than normal to switch to customer’s my account page
    2. When you do switch to customer’s account from Admin, you see all products from previous orders in the cart. It almost seems like the plugin caches all products (previously ordered) in the cart on the admin’s browser.

    Any ideas?

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Here is what John Blackbourn, the author of User Switching, has to say about this

    “This is a known issue with WooCommerce. Items in your cart are stored in your browser’s cookies, but they don’t get removed when you switch user. I don’t believe there’s any plan to fix the issue in WooCommerce, and there’s nothing that User Switching can do to help.”

    https://wordpress.org/support/topic/caching-issue-after-woocommerce-latest-update/#post-10022086

    Any solutions or plans to resolve this?

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Right, this has to do with browser cookies, sessions, and the persistent user cart cache.

    Doubtful there is much to do here without interrupting other behaviors (like how carts are restored when a user logs into their account).

    My recommendation would be to continually open up an incognito browser window before switching accounts, then close it and open up another before switching to the next user.

    Or, find a way to avoid needing to user switch via adding more admin controls for whatever it is you are doing.

    That’s the lousiest excuse I have heard in a while form a so-called engineer. avoid the problem as opposed to find the right solution. I see your problem solving approach!

    A REAL developer took a look this and took him literally a few minutes to figure it out.

    For users having the same issue, no need to take his advice. Here is your solution. I am sharing with you free of charge.

    add_action( ‘switch_to_user’, ’empty_woo_cart_user_switching’ );
    add_action( ‘switch_back_user’, ’empty_woo_cart_user_switching’ );
    function empty_woo_cart_user_switching() {
    WC()->cart->empty_cart();
    }

    ?>

    • This reply was modified 1 year, 7 months ago by  Laurendo.

    Hi Laurendo,

    I also have this problem and tried your code, but it’s not really working.
    Are you sure your code is not missing anything?

    Thanks in advance.

    After the latest woocommerce update it’s not working on Chrome but still works on Firefox.

    Too bad 🙁
    Thanks for the info!

    Since the original thread (https://wordpress.org/support/topic/user-switching-plugin-woocommerce-not-clearing-cookies/) was closed and this report was marked as “resolved” on User Switching side as well (https://wordpress.org/support/topic/caching-issue-after-woocommerce-latest-update/) and now marked as “resolved” here, well I guess we won’t have a solution any time soon.

    A year and so after we are still dealing with this, I appreciate old the hard work that’s been done on both sides, Woocommerce and User Switching.

    But come on! User Switching is one of the most useful tools for woocommerce store developers and for store owners. There should be a collaboration to get this resolved rather than bouncing the ball back to the each other’s field.

    Not sure how this issue got marked solved. The problem still persists.

    miketheteacher

    (@miketheteacher)

    Anyone had any success with this lately?

    For me the problem has only gotten worse – now after switching users the cart displays, for example, one item at $200, even after multiple refreshes, but then after the payment is processed, it’s sometimes 10X that amount.

    It’s quite embarrassing to have to continually refund customers for mistaken purchases.

    Laurendo

    (@laurendo)

    No the problem still persists and no one gives a damn. Woocommerce folks choose to ignore this issue.

    Use firefox when you switch, just make sure to go to clear Browsing & download, cache, and cookies history EVERY TIME from History > Clear Recent History.

    Hope that helps.

    miketheteacher

    (@miketheteacher)

    Appreciate the reply, thanks.

    Has anyone tried an automated script that clears transients etc. after a set interval?

    Hello,

    the code below will allow you to load the persistent cart of the user you are switching to and get back your original cart when switching back :

    add_action('switch_to_user', 'set_cart_content_on_user_switch', 10, 4);
    add_action('switch_back_user', 'set_cart_content_on_user_switch', 10, 4);
    
    /**
     * Sets cart content when using the "User switching" plugin
     * code found in: woocommerce/includes/wc-cart-functions.php "wc_load_persistent_cart"
     *
     */
    function set_cart_content_on_user_switch($user_id, $old_user_id, $new_token, $old_token) {
      $saved_cart = get_user_meta($user_id, '_woocommerce_persistent_cart_' .   get_current_blog_id(), true);
    
      if (! $saved_cart) {
        return;
      }
    
      WC()->session->cart = $saved_cart['cart'];
    }

    @arnaudfmagina
    Works!
    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘caching issue when switching to user’s account’ is closed to new replies.