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:


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=*

11 responses to “Too many wc_sessions in WooCommerce?”

  1. anamika

    We have installed Woocommerce in wordpress multisite. Before mapping domain everything worked fine. After domain mapping Add to cart is not working. When we select a product and press add to cart button page gets reloaded and says your cart is empty.

    When i tried above process by login to the site then it worked perfectly. Issue rises when user add products to their cart without login. I think the problem with cookies or session. Can you please provide me solution to resolve it.

  2. ewroman

    Hi Remi,
    Thank you for your all posts (they are all useful).

    My woocommerce sites option table is growing with “_transient_wc_ln_count…”, “_transient_timeout_wc_ln_count…” and “transient_timeout_wc_average_rating…”, “_transient_wc_rating_count”
    entries. How can I stop these entries? Because they slow down my server.

    Thank you very much.

  3. turbo

    Hi Remi,

    When adding the user agent code to my .htaccess file, I get a fatal error.
    could you please give more detail on how to properly add this code to the .htaccess file.
    Thanks mate.

    1. SaulBW

      Clearly he is just as confused as you. That snippet should be placed in a “robots.txt” file in your site root, not your “.htaccess” file.

  4. El Stupid

    I guess the code for .htaccess was meant for robots.txt. This is a typical robots.txt instruction. So create that file, insert the statement and save it to your webroot.

  5. bluesurf101

    We added the Disallow: /*add-to-cart=* to our robots.txt but noticing that a lot of session are still being created.

    We have the woocommerce wishlist plugin and looks like the sessions are related to that.

    Right now, visitors have to register on our site to create new wishlists so I’m not sure why these sessions are being created.

    Any idea on how to stop bots from creating wc_sessions that are related to the woocommerce wishlist plugin?

    btw – I really appreciate this post

  6. alemarengo

    Hi Remi!
    You SHOULD definitely correct the .htaccess wrong reference to robots.txt, otherwise one risk to mess things up… :)

  7. […] works and how your URL structure is configured, but once you know those two things, you can follow this excellent guide to apply the modifications on your own […]

Leave a Reply