WooCommerce Session & Cookies Usage

Today’s topic of discussion is, How to use sessions and cookies in WooCommerce. This programming based tutorial will guide you how to set the session, get session, and unset session.

You can access session class object by simply calling:

Set Your session:

wc()->session->set({your session},{Your value });

Get your session:

wc()->session->get({your session});

unset your session:

wc()->session->set({your session},{});

Store Session data:

Yes, WooCommerce stores the cart in database table {your dB prefix}

_woocommerce_sessions.

It retains the data for 2 hours only. After every 2 hours, your cookie and cart will expire if you are not a logged in user.

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!