• If you browse the site not logged in, the choose something to buy (put it in the cart), then when you go to the checkout page, if you login, you loose what was in your cart, and if you had something in your cart from the previous time you were logged in, that then is the new item in the queue to buy.

    While it does show in the “Your Order” portion of the page, if you don’t think about the fact that it might have just changed because you logged in, then you’ll buy the stuff that WAS in the cart (old), not the new things that you intended to buy. I had to make a couple refunds in the past month or so because the customer said they accidentally bought the wrong thing. I’m thinking that Woo Commerce did the bait and switch on them causing the problem.

    The customer thinks they goofed because previously they did look at and consider buying that product (old cart content), now that they ended up with it, but that’s not what they selected this time to buy. I’ve tested this a couple times and if I clear all cache and browsing data it seems to do the bait and switch. If I just logout, add something to the cart, and log back in, then it just pops in the old cart content on top of the new item selected to purchase. Basically adds the old cart to the new cart.

    That still means the customer is buying things they did not intend. I think this is a bug with Woo, and I think it’s a big problem. To me, the right solution is to ask the customer what they want to do with the item conflict. Either way, it absolutely should NOT change their cart content in the middle of a purchase.What can we do to fix this?

    The only place our users can sign in is on the checkout page… using the
    “Returning customer? Click here to login.” message/link. So, ideally when they login it should discard any items that were in their cart the last time they logged in.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter Davood Denavi

    (@binarywc)

    After doing some digging through the support forum here on wp.org I found this thread: https://wordpress.org/support/topic/persistent-cart-mixing-between-users/.

    For now, the function mentioned in that thread is an acceptable temporary fix. My customer would prefer a more permanent fix if one exists though.

    Thank you in advance for any help and/or suggestion on how to get to a more permanent fix.

    Hello,

    By default, WooCommerce does not clear cart upon user login. I’ve also tried this on my test site which has the latest versions of WordPress, WooCommerce and Storefront(default) theme, and I could not reproduce the same behavior. So I believe the issue in your case is caused by a conflict with theme or another plugin. I’d recommend running a full conflict test to determine what is causing this issue.

    Here’s how to do a conflict test: https://docs.woocommerce.com/document/how-to-test-for-conflicts/

    • This reply was modified 4 years, 7 months ago by MayKato.
    Thread Starter Davood Denavi

    (@binarywc)

    @maykato, I have done a lot of testing already… and I think you misunderstood what I am saying is happening.

    What happens is the cart is saving when logged in… then when someone comes back to the site a few hours later after logging out and adds something to the cart without logging in and goes to the checkout page before logging in the persistent cart feature of WooCommerce merges the cart with the old cart.

    The site owner (not me) said that the fix I found in the other thread which I mentioned in my last post is what he was looking for. I feel that that fix is a temporary one though. Is it?

    Note: The root of the problem is the logged merges with the logged out cart if the user is logging in from the checkout page. This should not be happening.

    Plugin Support abwaita a11n

    (@abwaita)

    Thanks for the clarification, @binarywc.

    The root of the problem is the logged merges with the logged out cart if the user is logging in from the checkout page. This should not be happening.

    This is actually the default inbuilt behavior in WooCommerce. When you log in to an account and add an item to cart then logout, the cart persists in your account. If you add another item to cart when logged out and log in again during checkout, the expectation is that items you had previously added to cart will be merged with the current items in cart.

    There have been workarounds via custom codes by users who’d prefer to have the cart cleared when a user logs out. Here’s one workaround – https://bucketpress.com/disable-woocommerce-persistent-cart/.

    If you’d like to suggest this as an inbuilt feature in future WooCommerce versions, you could post it in our Ideas Board for others to vote on it and also for developers to see it.

    Hope this helps.
    Thanks.

    Thread Starter Davood Denavi

    (@binarywc)

    BINGO!!!!
    When a user is logged out then logs in from the checkout page their cart shouldn’t merge at all, the logged out cart should be all they are shown on the checkout page since they aren’t logged in before giving their payment info.

    There’s an issue with cart_hash or persistent cart that is causing the issue described in my original post!

    Plugin Support abwaita a11n

    (@abwaita)

    Hi @binarywc,

    When a user is logged out then logs in from the checkout page their cart shouldn’t merge at all, the logged out cart should be all they are shown on the checkout page since they aren’t logged in before giving their payment info.

    Just to clarify, the opposite of what you’ve said is the inbuilt behavior. If there are items sitting in a customer’s cart on their account and they’ll be shown during checkout alongside other items added to cart when the user was logged out.

    The article I shared gives a workaround to have the cart cleared when one logs out.

    I hope this clarifies further.
    Thanks.

    Thread Starter Davood Denavi

    (@binarywc)

    I understand that by default Woo uses the persistent cart. The workaround mentioned in the article you linked to is something I tried before starting this thread but it was still not working as I was expecting it to.

    There is an issue with the cart_hash not resetting correctly that is why I tried the fix in the thread I linked to in my second post which ultimately did fix the problem. However, I feel that even that is still only a temporary fix.

    Is the fix in the thread I linked to a temporary work around or will that be be a permanent fix that’ll cause the cart_hash to reset correctly when the user logs in from the checkout page?

    Plugin Support abwaita a11n

    (@abwaita)

    Hi @binarywc,

    Is the fix in the thread I linked to a temporary work around or will that be be a permanent fix that’ll cause the cart_hash to reset correctly when the user logs in from the checkout page?

    Checking the other thread you referred to, I see the issue there isn’t quite the same as this one. The thread starter reported an issue of carts from different users mixing while on this thread, the reported issue is that the cart is not clearing after a user logs out.

    That said, there are several suggestions on that thread, is it possible to share the particular one you’re referring to so that we can take a closer look and advise further?

    Thanks.

    Thread Starter Davood Denavi

    (@binarywc)

    Again as I said a few days ago the fix suggested in the article you linked to in this thread did not work to resolve the issue on many site that I manage. I found a different article before this thread got a reply from @maykato which suggested the same exact fix and tested it. That is why I did some digging in the support forum here as I mentioned in my first reply.

    The fix mentioned in this post fixed the problem I was having and you still have yet to answer the question I asked here:
    Is the fix in the thread I linked to a temporary work around or will that be be a permanent fix that’ll cause the cart_hash to reset correctly when the user logs in from the checkout page?

    It is a simple question to answer I am confused why you keep going in circles with me rather than just answering the question I asked. Either the fix that solved my problem in the other thread is a permanent fix or it is a temporary work around. Please let me know.

    Plugin Support abwaita a11n

    (@abwaita)

    Hi @binarywc,

    Apologies for the delay here.

    Thanks a lot for clarifying on the said fix. On the thread linked, I’d seen multiple fixes shared by different users, that’s why I wanted to be certain about the one you were referring to.

    For quick reference, I’ll post the code given by the user ck-macleod here:

    /* CKM 2018.05.17 : PREVENT USER CARTS FROM BEING SHARED WHEN USER SWITCHING
    
     * from https://wordpress.org/support/topic/caching-issue-when-switching-to-users-account/#post-10075015
    
     */
    
    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();
    
    }
    
    /* END USER SWITCHING ACTIONS */

    Now coming to your question, the response by the user is not really a WooCommerce fix but rather a workaround for users that have the User Switching plugin and want to have their user carts cleared each time they switch users.

    The hooks targeted in the custom code (switch_to_user and switch_back_user) are also part of the User Switching plugin, not WooCommerce. As to whether this is temporary or permanent, it will depend on whether these targetted functions change. I might not be able to confirm this since they are from a third-party plugin.

    I hope this clarifies, let me know if anything else is needed.
    Thanks.

    Thread Starter Davood Denavi

    (@binarywc)

    That answers my question. However, I did not make this clear earlier but we do not want to install another plugin. Unfortunately, if the fix I used is just a work around that means the cart_hash needs to be completely reset on login to pull in only what was in the logged in cart. That is not going to be fixed by any user switching plugin. I did same testing with a user switching plugin that I use on a different website that I manage and that did not fix the cart_hash issue that was causing carts to merge.

    Is there something that would be a permanent fix where we could have the option to reset the cart_hash on login in the WooCommerce settings by adding code to our child theme’s functions.php file?

    Thank you in advance.

    • This reply was modified 4 years, 7 months ago by Davood Denavi.
    Plugin Support slash1andy

    (@slash1andy)

    Automattic Happiness Engineer

    Hey again!

    Is there something that would be a permanent fix where we could have the option to reset the cart_hash on login in the WooCommerce settings by adding code to our child theme’s functions.php file?

    There’s not anything that we have that would do what you are wanting to do.

    The best bet would be to have a developer write something like this for your site.

    We highly recommend contacting one of the services on our Customizations page (https://woocommerce.com/customizations/)

    I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter Davood Denavi

    (@binarywc)

    Thanks for the reply. I am a developer myself. Please do not tag this as resolved. It is not resolved until I find a permanent fix that doesn’t require a third party plugin. Workarounds are nice but I want a permanent fix.

    For now I’ll use the workaround mentioned above as a temporary fix until I find something permanent.

    If after talking to my client he says not to worry about it any further I’ll tag the thread as resolved myslef.

    Mirko P.

    (@rainfallnixfig)

    Hello @binarywc,

    It is not resolved until I find a permanent fix that doesn’t require a third party plugin. Workarounds are nice but I want a permanent fix.

    According to the forum guideline we set threads to resolved status if we haven’t heard back from you in over a week or no one else has been able to help you out in that same time span:

    https://wordpress.org/support/topic/guide-to-the-woocommerce-forum/

    This forum is for the default functionality of WooCommerce core and customizations or added functionality falls outside the scope of our support policy (https://woocommerce.com/support-policy/). We’re going to leave this thread open though for a while to see if anyone is able to chime in to help you out.

    Since this is more of a development-oriented issue you’ll want to also try the following channels:

    Lastly, as previously mentioned by @abwaita, if you’d like to suggest this as an inbuilt feature for future versions of WooCommerce core, you could post it in our Ideas Board. The more popular an idea becomes, the more of a priority it is for our developers to review.

    Thanks.

    Thread Starter Davood Denavi

    (@binarywc)

    Again, I already said I started this conversation over in slack and that I am a developer myself. Another thing I said we will not use a third-party plugin for this, in saying that I was also was saying we will not use another plugin to do this.

    All of that said, I have spoken to the client and while he things it is an okay solution as a workaround. I am still going to research further and look for a permanent solution because I do not want to leave a workaround in place that could break. I will update you guys within a week so please do not tag this as resolved because in my book it is not actually resolved yet.

    Thank you.

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Checkout issue after logging in’ is closed to new replies.