Hello friends, today in this tutorial we will learn how to remove wc_sessions in WooCommerce. First, we will discuss why we need to remove these sessions from WooCommerce. These sessions make wp_options table heavy in size. These sessions _wc_session_xxx and _wc_session_expires_xxx entries are stored in wp_options table. There are two reasons behind this, below they are:
- Cron tasks not working on site
- A bot is crawling your site and creates sessions on the fly
That’s the reason, _wc_session_xxx and _wc_session_expires_xxx entries stored in wp_options table and make your website Database heavy.
We can avoid the bots to create these sessions while crawling the website. What we have to do is we need to add the following code in robots.txt file, you can find this file in the website root directory.
User-agent: * Disallow: /*add-to-cart=*
Let’s see how we can remove these sessions from the WooCommerce. There are two ways to do this, below they are:
- Through WordPress Dashboard
- From phpMyAdmin
#1 Through WordPress Dashboard
From the Dashboard, WooCommerce provides Tool feature through which we can delete these Sessions. Here are the steps, please follow:
- Login to your website Dashboard. Click Status, sub-menu of WooCommerce, see below screenshot…
- On WooCommerce Status page, click on Tools tab, Find Clear customer sessions and beside this you will see Clear button, see below screenshot…
- Once you hit Clear button, all sessions will be deleted automatically.
- But sometimes, Database is so big that process of deleting session entries fails because of either low PHP Execution time or low Memory limit. In that case we have to delete these sessions from phpMyAdmin.
#2 From phpMyAdmin
If your process fails from WordPress Dashboard then don’t worry we can delete these sessions from phpMyAdmin as well. What we have to do is to run MySQL query in the wp_options table. Copy below MySQL query and run in your database.
DELETE FROM wp_options WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'
At last, if you want to avoid wp_options table to become so big then make sure that cron aren’t disabled on your website, to do so please check your WordPress install does NOT contain below the line, if so then remove it or make FALSE:
define('DISABLE_WP_CRON', 'true');
Friends if you follow these steps, your website will definitely load fast. Please let me know through your comments if this article helps you. Keep learning.
4 thoughts on “How to Remove wc_sessions in WooCommerce”
will this delete my stored carts of my customers
Is this safe to use, will it effect on my previous clients data in woocommerce, i have 3.8 GB in wp_woocommerce_sessions table which is affecting my site performance
Yes Satinder, It’s totally SAFE. No, it will not affect on your client data.
Keep Reading, Learning, and Sharing.
Thanks
No, Satinder. It will only delete your store sessions created from then customers. Means when customer go to your cart and exit without checkout that time session created in your woocommerce database table for long time and that is useless for you and that’s the reason website speed slow down.