There is annoying problem with WooCommerce (version 2.x) that "Add to Cart" stop working for un-authenticated user.
There is annoying problem with WooCommerce (version 2.x) that "Add to Cart" stop working for un-authenticated user.
I experienced this problem and this is scenario:
Un-authenticated user go to Product Detail page, click on add-to-cart button then a message notify that item is in cart, go to cart and nothing there. It is the same result if user click add-to-cart button on Category page.
Relating to this problem, most of reported topics on the Internet discuss about Cache Plugins and configuration. However, I did not use any cache plugin, even server-side caching as Memcache, Varnish.Checking the cookies, I found something that cookies are missing:
wp_woocommerce_session_445cef8456... |
woocommerce_items_in_cart |
woocommerce_cart_hash |
Wow, after few time of pulling-hair, I found a solution of phildom that help me get rid of this bug
You can open the header.php file in activated theme's folder.
Add PHP script at upper most position:
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Add meta tag in header:
<meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" />
This solution disable the PHP cache and Browser Cache. It would not be solution for heavy-traffic website which requires the cache to speed up response time.
If you have any idea about this bug, contact me and discuss about the better solution