How to Remove wc_sessions in WooCommerce

Remove woocommerce sessions

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:

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

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

  1. Login to your website Dashboard. Click Status, sub-menu of WooCommerce, see below screenshot…
    WooCommerce Status
  2. On WooCommerce Status page, click on Tools tab, Find Clear customer sessions and beside this you will see Clear button, see below screenshot…
    Clear WC Sessions
  3. Once you hit Clear button, all sessions will be deleted automatically.
  4. 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.

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

All the tools you need to build professional forms online.

Create custom web forms to capture leads

Collect payments

Automate your workflows

Build your business online

Create custom web forms to capture leads, collect payments, automate your workflows, and build your business online