I try to learn the cookies of WooCommerce, for do any function operating by products the added to cart. I wrote in console document.cookie
And I get this data:
woocommerce_items_in_cart=1;
woocommerce_cart_hash=500d17f6c010b62b25c3f52893be945d;
I understand that the cookie "woocommerce_cart_hash
" contains the products in cart, but I don't understand how to get the name of the product. What is it 500d17f6c010b62b25c3f52893be945d
Any help would be appreciated.
As you will see below,
woocommerce_cart_hash
doesn't contains the products in cart, because there is a third more complex cookie related to WooCommerce sessions DB table.The data is not stored in the cookie herself but in a corresponding reference located in DB WooCommerce session (see below for details)...
You have also to note that WordPress enable some local data storage.
1) Woocommerce set 3 cookies when a non logged user add something to cart:
2) And in DB table
wp_woocommerce_sessions
a session is generated at the same time:I can't explain all core processes (for that you will need to look in php core files).
But if you look to
wp_woocommerce_session_…
cookie value you will see that you can cut it with%7C%7C
substring, so we get here 4 substrings for this cookie value:If the user come back and delete one item in his cart:
woocommerce_cart_hash
cookie value changeswoocommerce_items_in_cart
cookie value don't changes as an item remains in cart.wp_woocommerce_session_3413758cad2ada414127ffee7347e40f
cookie value don't changes.wp_woocommerce_sessions
TABLE, the session ID6
has been deleted/replaced by a new generated session ID is that reflects the cart changes (only one product).References: