WooCommerce | After logout the cart getting empty - wordpress

I am totally new on WooCommerce, and I have a client with an "issue", that I am not sure if that is really an issue.
What he described to me, was the following scenario:
The client comes in the web site,
The client add some product in the cart,
Then he goes in the cart, and he perform a login
then the client logou, and the cart is getting empty.
So the question is, this behavior is the normal procedure for WooCommerce ? If so, is there a way to avoid the empty cart after the user is getting log ou of his account ?

There is a setting "clear cart on logout". Probably is enabled.

Related

Clear cart on headless WooCommerce

I have a Nuxt frontend for a WooCommerce store. What would be the best way to clear the cart in this setup?
My current (only) go at this is to clear the cart using ajax call to WordPress on thank-you page, that does this:
WC()->cart->empty_cart(true);
WC()->session->set('cart', array());
WC()->session->set('order_awaiting_payment', null);
But this seems reliant on too many factors and if any of them blows, the end user will be left in doubt.

woocommerce password reset will empty cart

Is it normal that if I reset my password and then login again to the store it will empty my cart?
These are steps I have taken:
Login to the woocommerce store
add a product to the cart
logout from the store
reset my password
login again to the store with the new password
the cart is now empty.
I believe that it is the password rest that triggers the cart to be emptied. Why does it work this way? I suppose it is a security issue.
If I don't reset my password and logout and then login again, the cart will contain the product I previously added. This is fine.
Just wondering why the password rest will empty the cart.
Just wondering why the password rest will empty the cart.
This is normal behaviour. like Ozgur said, the user session is "cleared" upon resetting the password.
Why does it work this way? I suppose it is a security issue.
It is indeed a security based behaviour. If you want to learn/understand a bit more about what is happening, you can take a look at what are Nonces.
Source # https://codex.wordpress.org/WordPress_Nonces.
To get around that behaviour and remain secure:
You could save the user cart info as a cookie/LocalStorage (JS based solution) (More # https://www.w3schools.com/jsref/prop_win_localstorage.asp) and save the product ID that are in the user cart...
You could also save it as a user metadata (PHP based solution) and serve it back to the user in that specific case.
You could for example, when the user log back in, present him a popup window and a button to add all the items to his cart once more OR simply redirect him straight away to his cart by adding all the items. You can take a look at the link bellow to add products via url.
Source # https://gist.github.com/lukecav/ab9dbdee88de686ce6b59c264cde8970

Customizing Woocoomerce Cart page

Hi I want to add checkbox on my Cart page of woocommerce when user check the box it will automatically subscribe them for my product. I have bought woocommerce subcriber plugin but I don't know how to add checkbox which will have this functionality in cart page.
I will try to answer to the best of my knowledge given that I am not proficient with woocommerce. But the general idea is that, you add your checkbox on the cart page of the theme and pass the the value via form data(like name="subscribe" value="True/false") to the data handler(most probably the next page in the checkout cycle which would be delivery or payment options page), which will then call the plugin and pass the subscriber info to it. I would say that it would make sense to put the checkbox where you collect customer info but hey your site, your choice.
Sorry if this is a very generic answer and not a detailed one. I am very new to this myself. Best of luck.

How to make woocommerce add cart function works for not logged in users?

WC()->cart->add_to_cart(8, 1);
I am using the above code to add dynamic products in the cart. It's working fine when I am logged in but it fails to add products while I am not logged in. How to fix this?
Answering 2 years later in case anyone has a similar problem.
I solved this by adding first adding the item to the cart, and then setting the woocommerce session cookie:
wc()->cart->add_to_cart($id);
wc()->session->set_customer_session_cookie(true);

How to set woocommerce checkout form values to empty

I am using Woocommerce plugin for a WordPress site. But when as user I checkout I can see form populated with last user's details. How to set form entries to blank in Woocommerce. Please help.
Fields are pre-populated with last user's detail. Is there a way to avoid this?
Not sure with your exact issue , but there might be two possible situations in your case.
You might me logged in with same user and then trying to
checkout, as woo-commerce will fetch the details of currently active
user and auto fill it during checkout.
Fields might get auto fill from your browser cache , try to checkout using another browser or
by clearing cache , if its due to cache than that's not an issue at
all, as it your browser functionality which keep the data store
temporarily for your next usage.

Resources