Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate cart in Woocommerce sessions after logging in #23686

Closed
tatusah opened this issue May 13, 2019 · 2 comments · Fixed by #23687
Closed

Prevent duplicate cart in Woocommerce sessions after logging in #23686

tatusah opened this issue May 13, 2019 · 2 comments · Fixed by #23687

Comments

@tatusah
Copy link
Contributor

tatusah commented May 13, 2019

The issue
When a guest user logs in to user account while there are products in the cart the cart content is copied over to a new session in the woocommerce_sessions table where the key is the logged in customer_id. The guest session cart stays in the table also. Thus there are now two instances of the same cart. This leads to problems when the store is selling unique single quantity items and has availability checks in place to prevent multiple customers from purchasing the same item either with a custom code or by using something like Cart Stock Reducer plugin. https://wordpress.org/support/topic/product-in-cart-not-available-after-logging-in/

Solution
I propose deleting the guest session after user logs in. The cart content that the user had in the cart before logging in should still carry over to the logged in session and be merger with possible persistent cart content. I was already able to built a working solution by customizing the class-wc-session-handler.php file where the guest customer id is carried over to the function where the cart content is copied and after the copying is done then the redundant guest sessions is deleted with this key. I'll submit a pull request.

Alternatives
Alternative solution might be to update the guest user session with the logged in user details instead of copying the cart.

@tatusah
Copy link
Contributor Author

tatusah commented May 13, 2019

Does anyone who has more extensive experience of Woocommerce code foresee any issues with deleting the guest sessions after login?

@rodrigoprimo
Copy link
Contributor

Closing as there is a PR already for this issue: #23687

kloon added a commit that referenced this issue Jul 15, 2019
Delete guest cart session if user logs in, solves #23686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants