Support » Plugin: WooCommerce » Persistent cart mixing between users

  • Resolved Tii

    (@tii)


    hello,

    we have had some issues with the cart persistence in Woocommerce where different customers share the same cart.
    Strangely, their cart is the same as other users and gets filled by all the users request, which lead to a cart with 20 or more items that cannot be emptied as every user sharing the cart will re-persist it.

    For the moment, I de-activated the cart persistence to avoid this problem but I really need to find a real solution for this.

    I am using the latest WordPress and Woocommerce with a few plugins and even custom made one but nothing (that I know of) is messing with sessions.

    In terms of caching, the website is on Cloudflare with Caching set to “no query string”, we also have a nginx fast-cgi cache but it will not be ative once users are logged-in.

    I also added the object-cache.php from here : https://wordpress.org/plugins/memcached/ but I still had the problem when removing this.

    I had one the problem in local and it went back to normal after intensive cookie clearing so I guess is related to the cart hash in the cookie but I can’t find way to reproduce it intentionally.

    Anybody had the same issue?
    What should I do to find the source of the problem?

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

Viewing 15 replies - 1 through 15 (of 30 total)
  • Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hey @tii

    My suggestion here would be to dig into your caching set up more, this is most likely the culprit here.

    We have some support notes about caching and WooCommerce here – https://docs.woocommerce.com/document/configuring-caching-plugins/

    Maybe reach out to your host? You’ll be surprised what caching they drop into sites that you don’t know about.

    Thanks,

    Thanks for the answer but I am the host.
    The website is running on a VPS with LEMP. The only cache in places are:
    – nginx fast cgi
    – cloudflare
    – object-cache
    I tried to find the problem and I could easily reproduce it in my local environment without any cache activated.
    Here a the reproduction steps:
    – Connect with user A from browser A
    – Add a product in cart with user A
    – Open Browser B
    – Login with user B
    – Add a product in cart with user B
    – Clear all cookies and Browser storage in Browser B
    – Login with user B
    (it does not work every time I do it but repeating the steps a few times allowed me to reproduce it every 5 times or so)

    The carts somehow merged both carts into one and adding products from one user add to the other user’s cart, checking the cookie shows me that they both have the same cart hash which explain the problem.

    I really wonder how it is possible for the cart hash to be the same without any cache activated (local development environment with WP_DEBUG on);

    Im seeing this on multiple sites now – wondering is any more has been done here

    right now, I have disabled the persistant cart like this :

    function d6_remove_persistent_cart($value, $id, $key) {
        if ($key == '_woocommerce_persistent_cart_1') {
            return false;
        }
        return $value;
    }
    add_filter('get_user_metadata', 'd6_remove_persistent_cart', 10, 3);
    add_filter('update_user_metadata', 'd6_remove_persistent_cart', 10, 3);
    add_filter('add_user_metadata', 'd6_remove_persistent_cart', 10, 3);

    but I would like to re-activate it at one point…

    Zandy Ring

    (@zandyring)

    Automattic Happiness Engineer

    Hi Tii,

    Hmm, that’s an interesting issue – sorry that it’s happening! Have you done any plugin conflict testing to see if there’s a particular plugin or theme that’s causing the issue? I realize with the irregularity of being able to reproduce it, it’s difficult to test.

    Is this only happening when customers share a browser/computer?

    We’re also seeing this currently on a limited basis on one of our client’s sites. Investigating further. While we are using object caching in w3-cache, this issue hasn’t been continually present, so we haven’t seen a pattern present yet. Running WooCommerce 3.2.5

    Addtl info: This is occurring for two completely different customers, in completely different browsers.

    Hi. I don’t know if my problem is the same. But I have 2 advices at the top of wordpress and they are very annoying. They are:
    1. You need to install default WooCommerce page: Cart Page.
    2. You need to install default WooCommerce page: Checkout Page.
    I look into my php error log and find this:
    [21-Mar-2018 08:03:44 UTC] Advertencia de PHP: “carro” de desplazamiento de cadena ilegal en /home/debander/public_html/conunicornios.es/wp-content/plugins/woocommerce/includes/class-wc-cart- session.php en línea 80

    [21-Mar-2018 08:03:44 UTC] Advertencia de PHP: array_merge (): El argumento # 1 no es una matriz en /home/debander/public_html/conunicornios.es/wp-content/plugins/woocommerce/includes/class -wc-cart-session.php en línea 80
    I do not use my cart or my checkout page in my web. So I don’t understand WHY they are there. And they don’t have the “X” to close them. Just stay there all the time… hope anyone have a solution. Thanks!!

    Ps. I have update woocommerce today but they are still there. All my versions are updated. I use woozone, yoast seo and Viking guard. I usually use chrome. And I have 2 more webs with same configuration and they work just fine. I don’t understand…

    @egfwill your issue has nothing to do with cart persistance…

    ok, I’m sorry.
    Regards.

    i actually faced same problem ….actually this problem is related to the theme cache or related to any other cache plugin…..but now i totally found the solution..
    colpy these three line into yout .htaccess file on the root of the wordpress

    RewriteRule ^wp-json – [E=NOCOOKIE:1]
    SetEnvIf REDIRECT_NOCOOKIE 1 NOCOOKIE=1
    Header always unset Set-Cookie env=NOCOOKIE

    and also add this code into yours child themes function.php

    add_action(‘woocommerce_before_checkout_form’, ‘dump_woocommerce_cart’);
    function dump_woocommerce_cart() {
    global $woocommerce;
    //print_r($woocommerce->cart);
    }

    function d6_remove_persistent_cart($value, $id, $key) {
    if ( $key == ‘_woocommerce_persistent_cart_1’) {
    return false;
    }
    return $value;
    }
    add_filter(‘get_user_metadata’, ‘d6_remove_persistent_cart’, 10, 3);
    add_filter(‘update_user_metadata’, ‘d6_remove_persistent_cart’, 10, 3);
    add_filter(‘add_user_metadata’, ‘d6_remove_persistent_cart’, 10, 3);

    this totally resolve my problem….
    i hope it will help..thank you

    We are having this problem – or what seems to be a version of this problem – with the Ajax cart on our site. We have eradicated all _wooommerce_persistent_cart_1 data from our database, and, within days, users start getting carts filled with never-selected items again. Though it’s possible, certainly, that the problem is tied up with peculiarities of the installation (an unusual substructure, layers of caching as well as custom coding), that others have been experiencing the problem and in about the same time frame that it newly arose at our site leads us at least to wonder if there isn’t a common answer.

    We’ve noted the solution provided in the most recent comment, but the re-write rule seems too general, since it applies very broadly to wp-json cookies, while the PHP seems to remove all persistent cart data altogether. The persistent cart is a function that users like!

    Anyway, if anyone has any further information on the origins or most likely specific origins of this problem, or even of a tightly focused solution, we’d love to hear about it.

    The site in question, in case anyone wants to try examining the problem from the outside, is https://www.gbes.com

    We are experiencing the exact same problem. The following request to the API seems to mess up the woocommerce cart sessions:

    function getProductInfo(){
       var url = '/wp-json/wc/v2/products/',
       auth = '?consumer_key=OUR_KEY_HERE&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1458225139&oauth_nonce=nVq4rX&consumer_secret=OUR_SECRET_HERE',
       url = url + $wcId + auth;
    
       $.get( url, function( data ) {
          $singleProduct = data;
          setProductInfo();
          setOrderButton();
       });
    }

    @kevin Walkeezy – we think that at our installation the problem recurred due to bleeding over of carts when using the User Switching plugin. We’re still not 100% sure that this was the problem, but we haven’t had any new complaints since 1) eradicating all of the cart data from the User Meta table and session table, and 2) adding a function that cleared cart data before and after User Switching.

    Fingers still crossed though.

    We are experiencing the same issue! There seems to be a WooCommerce Core bug? Were using no caching plugins of any kind.

Viewing 15 replies - 1 through 15 (of 30 total)
  • The topic ‘Persistent cart mixing between users’ is closed to new replies.