Support » Plugin: WooCommerce Cart Stock Reducer » Product in cart not available after logging in

  • I have noticed an issue where unique single item is not available for purchase when it’s added to the cart when user is in guest mode. Then after logging in the cart shows that the product is not available any more. So it seems that logging in starts a new session and the previous session has the products reserved even though it’s the same customer.

    To reproduce:
    1. create a simple product with stock quantity of 1
    2. navigate to the product while not logged in and add the product to cart
    3. navigate to checkout page and log in to the user account
    => after logging in the notice of product unavailability is shown and the product can’t be purchased

    How could this be fixed? If cart stock reducer plugin is disabled then the user can add product in guest mode and login with the product still available in cart.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author James Golovich


    This is an interesting one. What is happening is the cart gets copied to the logged in users session so now there are 2 identical carts.

    It seems like the best course of action will be to remove the “anonymous” session when the user logs in but I’ll have to do some digging to see if WooCommerce will make it easy to happen.

    Yes, definitely interesting issue. I’m not totally sure when this issue has started to occur. Currently running WC 3.6.2 and v3.08 of your plugin. It could very well be that this issue started with the new WC as based on this there was introduced new things related to the session handling.

    It would nice if you can look into this as all our products have single quantities and this issue confuses a lot of customers who start shopping in guest role and then login during checkout process.

    Thanks again!

    Plugin Author James Golovich


    I suspect the issue has been around forever since WooCommerce doesn’t really care about abandoned sessions.

    I’ve been digging into it since earlier and haven’t come up with a solution yet. I’m not sure when I’ll have available time to dig in some more, I was hoping it would be a quick fix but I’ve got to move onto another project right now.

    I managed to create one possible solution to this issue by customizing the Woocommerce Session Handler. This is the customized version

    It now stores the original guest session key to variable in the init_session_cookie phase and this variable is used to destroy the guest sessions once the new logged in user based session is created to wp_woocommerce_sessions table by the save_data function.

    What do you think? Is this viable solution? Based on my testing the guest user session gets deleted fine and the customer’s cart gets passed to the logged in session. Only thing is that after logging out the cart is empty. However, in our use case this doesn’t matter.

    How to make this solution permanent so that it doesn’t get overridden when Woocommerce gets updated? Should I get this accepted to the Woocommerce core? Or would it be better if you could extend the WC_Session_Handler class and override the default behaviour?

    Plugin Author James Golovich


    At a quick glance that looks like it should work. If you did try to get them to accept the change they would likely complain about the code styling/formatting.

    I was hoping to find a way to handle it using some existing hooks, but I haven’t had any available time to dig into it.

    I have the pull request in review process here

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Product in cart not available after logging in’ is closed to new replies.