Hello friends!
Today, in this tutorial, we will learn how to remove sessions in WooCommerce. First, we will discuss why we need to remove these sessions from WooCommerce. These sessions make the wp_options table heavy in size. WooCommerce stores the _wc_session_xxx and _wc_session_expires_xxx entries in the wp_options table.
There are two reasons behind this, and below are:
- Cron tasks are not working on the site
- A bot is crawling your site and creating sessions on the fly
That’s the reason, _wc_session_xxx and _wc_session_expires_xxx entries are stored in the wp_options table and make your website Database heavy.
We can avoid the bots from creating these sessions while crawling the website. What we have to do is we need to add the following code to the robots.txt file. You can find this file in the website root directory.
User-agent: * Disallow: /<em>add-to-cart=</em>
Let’s see how we can remove these sessions from WooCommerce. There are two ways to do this. Below are:
- Through the WordPress Dashboard
- From phpMyAdmin
1. Through the WordPress Dashboard
From the Dashboard, WooCommerce provides a Tool feature through which we can delete these Sessions. Here are the steps, please follow:
- Log in to your website Dashboard. Click Status, sub-menu of WooCommerce, see screenshot below…
- On the WooCommerce Status page, click on the Tools tab, Find Clear customer sessions, and beside this, you will see the Clear button, see screenshot below…
- Once you hit the Clear button, all sessions will be deleted automatically.
- But sometimes, the Database is so big that the 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 the WordPress Dashboard, then don’t worry, we can delete these sessions from phpMyAdmin as well. We need to run a MySQL query on the wp_options table. Copy below MySQL query below and run it in your database.
DELETE FROM wp_options WHERE option_name LIKE '<em>wc_session</em>%' OR option_name LIKE '<em>wc_session_expires</em>%'
At last, if you want to avoid the wp_options table from becoming so big, then make sure that cron isn’t disabled on your website. To do so, please check your WordPress install does NOT contain the line below; 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.
You May Like it
Discover more from Wordpress Tutorial for Beginner's
Subscribe to get the latest posts sent to your email.
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.