How to Remove wc_sessions in WooCommerce

Remove woocommerce sessions

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:

  1. Cron tasks are not working on the site
  2. 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:

  1. Through the WordPress Dashboard
  2. 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:

  1. Log in to your website Dashboard. Click Status, sub-menu of WooCommerce, see screenshot below…
    WooCommerce Status
  2. 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…Clear WC Sessions
  3. Once you hit the Clear button, all sessions will be deleted automatically.
  4. 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 &#039;<em>wc_session</em>%&#039; OR option_name LIKE &#039;<em>wc_session_expires</em>%&#039;

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.


Discover more from Wordpress Tutorial for Beginner's

Subscribe to get the latest posts sent to your email.

Share:

Facebook
Twitter
Pinterest
LinkedIn

4 thoughts on “How to Remove wc_sessions in WooCommerce”

  1. 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.

Please share your thought

Discover more from Wordpress Tutorial for Beginner's

Subscribe now to keep reading and get access to the full archive.

Continue reading