If you run WooCommerce on shared hosting and have a high number of users on your online store, this might put a lot of strain on your server. When extensively filled with session data, the size of the database’s wp_woocommerce_sessions table can reach 2 or 3 GBs.
How to Clear Cart Session Data
- Go to Dashboard > WooCommerce > Status > Tools
- Scroll down to the option “Clear customer sessions“
- Click “Clear” and confirm the operation.
This tool will remove all customer session data from the database, including any active shopping carts.
What happens when you delete Customer Sessions?
- Expire everyone’s carts immediately.
- Clear customer’s carts if they are currently on the site.
What is wp_woocommerce_sessions?
“wp_woocommerce_session” — helps WooCommerce to find the shopping cart data in the database for each visitor/customer. WooCommerce stores PHP Sessions in the wp_woocommerce_sessions database table. By default, it deletes the session data after 48 hours or two days. WooCommerce developers released a new WooCommerce session handling and storage mechanism, based on WP Sessions Manager, with the release of WooCommerce 2.5 in 2015. This mechanism resulted in the creation of wp_woocommerce_sessions. A table dedicated to client sessions that does not interact with other tables in the database. In the event of a serious error, losses should be kept to a minimum.
What is the default session expiration time?
The WooCommerce session expiration time is set to 48 hours by default. After 47 hours, WooCommerce will automatically check for client activity. This leaves the customer with a 1-hour window to extend their session.
What is considered customer activity?
To be considered “active” by WooCommerce, a client must simply load (or refresh) any webpage on your website.
How To stop customer sessions from being permanently stored
Unfortunately, these sessions are not always erased, and in some circumstances they remain permanently saved in wp_woocommerce_sessions, making this database extremely huge.
Most of the time, it’s a theme or plugin’s custom function that prevents automated deletion of expired sessions from wp_woocommerce_sessions.
If you are facing such a problem you need to carefully investigate all possible causes.
- SQL error
Check if there are any SQL errors occurring during the deletion process. This could be due to database corruption or misconfiguration.
- SQL permissions
Make sure you have necessary permissions to modify the wp_woocommerce_sessions table. Sometimes, incorrect permissions can prevent the deletion of data.
- Cron Job
WooCommerce utilizes cron jobs to perform various scheduled tasks, including session cleanup. Go to WooCommerce > Status and scroll down to WordPress cron. Make sure the green dot is visible.
- Theme / Plugin conflict
Disable any recently installed or updated themes and plugins one by one to identify if any of them are causing the issue.
- Exclude WooCommerce Sessions From Caching
Most caching plugins don’t include database caching. However, some do, and you must exclude “_wc_session_” from caching in those cases.
W3 Total Cache
This is done automatically in W3 Total Cache and can be accessed under wp-admin > Performance > Database Cache.
Go to WP Rocket → Advanced Rules and enter the following value in the Never Cache Cookies field:
Finally, the size of the wp_woocommerce_sessions table in the WooCommerce database might become a serious issue for online store owners, especially those who have heavy user traffic. WooCommerce customers can reduce the pressure on their servers and ensure optimal performance for their online stores by following these steps and taking proactive actions to clear and manage customer sessions properly.