Too many wc_sessions in WooCommerce?

In some cases, you can see that your wp_options table is growing too fast and is becoming huge because of WooCommerce. If so, you can see that the sql table is full of _wc_session_xxx and _wc_session_expires_xxx entries. These can happen because of two things:

  • Cron tasks aren’t working on your site
  • A bot is crawling your site and creates sessions on the fly

Hopefully, in the latest WooCommerce versions there’s a tool to delete these sessions:

clear-wc-sessions

But sometimes, the database is so big, that the process fails because of the PHP max execution time, or because of a lack of memory. In that case you can use the following MySQL query directly in phpMyAdmin:

DELETE FROM wp_options
WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'

And finally, to avoid the wp_options to become so big, make sure that cron aren’t disabled on your site, to do so check if your install does NOT contain this line of code:

define('DISABLE_WP_CRON', 'true');

If so, remove it.

One last thing, if you want, you can add the following code to the robots.txt file to avoid bots to create sessions while crawling your site:

User-agent: \*
Disallow: /\*add-to-cart=\*