Skip to content
TutorialOct 2026·8 min read

Clear WooCommerce sessions and clean your database without touching orders

The Clear customer sessions button empties every live cart. Delete only expired sessions and transients, trim autoloaded options and keep every order.

SmartWP teamThe people who build our plugins
Flat illustration of a database with old layers lifted away and the core locked

Level

Intermediate

Steps

4

Time

About 20 minutes

You’ll need

WordPress admin access and a fresh database backup. WP-CLI is optional.

To clear WooCommerce sessions safely, delete only the expired ones and leave live carts alone. WooCommerce does this itself twice a day, so a sessions table that keeps growing often means that job has stopped. The Clear customer sessions button in WooCommerce → Status → Tools goes further: it empties every cart, including the ones shoppers are filling right now.

The same rule covers the rest of a WooCommerce database clean-up. Expired transients can go, and so can autoloaded options left by plugins you’ve removed, while orders, order notes and customer accounts stay where they are. Each step also has a WP-CLI command if you prefer the command line.

Why is the WooCommerce sessions table so big?

WooCommerce keeps each shopper’s cart and checkout details in the wp_woocommerce_sessions table. A guest gets a row once they add something to the cart, and a signed-in customer gets one as they shop. Since WooCommerce 10.1, a guest’s session lasts 2 days and a signed-in customer’s lasts 7, and no plugin can stretch either beyond 30 days.

Twice a day, a scheduled action called woocommerce_cleanup_sessions deletes the sessions that have expired. The table balloons when that action stops running, so expired rows never leave, or when bots add products to carts and each visit leaves a session behind for two days. To check the first, open WooCommerce → Status → Scheduled Actions, search for woocommerce_cleanup_sessions and see whether it’s past due or has failed.

How to clear WooCommerce sessions and expired transients safely

These steps remove only rows that have already expired, so shoppers won’t notice. A quiet hour is still the best time to run them.

  1. 01

    Back up the database

    The clean-up steps delete rows, and a deleted row only comes back from a backup. If your host takes daily backups, check that today’s has finished, or start one by hand. Our guide to updating WooCommerce explains how to make a backup you can restore.

    With WP-CLI, one command exports the database. Save the file outside your web root, because it holds your customers’ details.

    WP-CLI
    wp db export ~/before-cleanup.sql
  2. 02

    See which tables have grown

    Find out where the space goes before you delete anything. Your host’s phpMyAdmin lists every table with its size, and this command lists them biggest first:

    WP-CLI
    wp db size --tables --all-tables-with-prefix --orderby=size --order=desc

    Watch wp_woocommerce_sessions and wp_options, where transients and autoloaded options live. If the wp_actionscheduler_ tables come out on top, old background jobs are taking the space, which is a separate clean-up.

  3. 03

    Delete expired sessions only

    Count the sessions that have already expired. If your tables don’t start with wp_, run wp db prefix to see the prefix to use instead.

    WP-CLI
    wp db query "SELECT COUNT(*) AS expired FROM wp_woocommerce_sessions WHERE session_expiry < UNIX_TIMESTAMP();"

    Then run the function that WooCommerce’s scheduled action calls. It deletes expired sessions in batches of 100 and leaves live carts alone.

    WP-CLI
    wp eval 'wc_cleanup_session_data();'

    Without WP-CLI, open WooCommerce → Status → Scheduled Actions, find the pending woocommerce_cleanup_sessions action and click Run under its name. If expired sessions pile up again over the next few days, the scheduled action isn’t running, and that’s the thing to fix.

  4. 04

    Clear expired transients

    Transients are cache entries that plugins store in wp_options with an expiry time. WordPress deletes expired ones once a day through WP-Cron, so they build up when WP-Cron is switched off without a real cron job in its place.

    Go to WooCommerce → Status → Tools, find Expired transients and click Clear transients. WooCommerce tells you how many rows it removed. The WooCommerce transients row above it has a button with the same label, but that one clears WooCommerce’s product and shop caches, which rebuild themselves, and leaves other expired transients where they are.

    WP-CLI
    wp transient delete --expired

    Expired transients aren’t autoloaded, so clearing them shrinks wp_options but leaves each page load the same. The options WordPress reads on every page are the autoloaded ones, covered next.

A conveyor feeding many cards, a few oversized, into a page
Autoloaded options load on every page, so a few large ones add up.

How to clean up WordPress autoloaded options

Autoloaded options are settings WordPress fetches in one query on every page load. Plugins add their own, and some leave them behind after you delete the plugin, so a store that has tried a lot of plugins carries a lot of them.

Since WordPress 6.6, an option bigger than 150 KB isn’t autoloaded unless its plugin asks for that, and the autoload column holds on, off, auto, auto-on or auto-off. Options saved before 6.6 keep their old yes or no, so an older store can still have heavy ones autoloading.

Tools → Site Health warns “Autoloaded options could affect performance” once the total passes 800 KB. To see which options make up that total, run this query. It checks all four values that mean the option loads on every page, because wp option list --autoload=on only matches on and yes.

WP-CLI
wp db query "SELECT option_name, LENGTH(option_value) AS bytes, autoload FROM wp_options WHERE autoload IN ('yes','on','auto-on','auto') ORDER BY bytes DESC LIMIT 20;"

Work out which plugin each large option belongs to; the name usually gives it away. If that plugin is gone or switched off, stop autoloading the option. The value stays, so nothing breaks if you reinstall the plugin later.

WP-CLI
wp option set-autoload <option_name> off

Leave WordPress’s and WooCommerce’s own options as they are. If an active plugin reads an option on every page, switching its autoload off only makes WordPress fetch it with an extra query each time. Once you’re sure a leftover is unused, wp option delete followed by its name removes it for good.

A stack of order receipts protected under a dome with a lock
Orders, customers and their history are never part of a clean-up.

What to leave alone when you optimize the WooCommerce database

Some clean-up plugins also offer to delete old orders or customers. Keep those: orders and order notes are your sales and tax records, and WooCommerce Analytics reads from them. Rows that belong to nothing are different: order items whose order is gone, or post meta without a post, can go once a tool has shown you what they are.

Deleting rows frees space inside a table, and the database reuses it for new rows, so the table stops growing even though its file on disk stays the same size. OPTIMIZE TABLE shrinks the file, but it rebuilds the whole table and can take minutes on a big store. Leave it for a quiet hour, or skip it.

Free ebook, 42 pagesThe Ultimate Checklist to WooCommerce OptimizationGet the checklist

Clean the WooCommerce database from the dashboard with Admin Powerups

If you’d rather not run commands, Admin Powerups, our set of WooCommerce admin tools, includes a database clean-up that never touches orders. Two of its power-ups handle the clean-up steps above. Both sit in the Performance group, only site admins can see them, and both carry the Advanced risk badge because some of what they do can’t be undone. Each tool page opens with a warning to take a backup first.

Database clean-up

Database clean-up finds and deletes what WooCommerce and WordPress leave behind: expired sessions and transients, orphaned order data, old revisions, spam and finished background jobs. Click Scan and every check shows a count, and View shows up to 10 example rows before anything is deleted. You clean one check at a time. Safe and Review checks ask for a second click, and Advanced ones ask you to tick I have a recent database backup and type “delete”.

Orders, order notes, guest customers and customer tags are never cleaned. Expired shopper sessions deletes only sessions past their expiry, the way WooCommerce’s own job does, so live carts stay. If you turn on Clean Safe items weekly, it clears expired shopper sessions, expired transients and term links to missing terms by default, once a week in the background.

Autoloaded options

Autoloaded options shows which options load on every page, how big they are and who probably owns them. A summary compares the total with the limit Site Health recommends, and the list holds the 100 largest, which you can filter by owner, including Inactive or removed.

Stop autoloading keeps the option and asks for a second click, and Autoload again under Recent changes undoes it. Delete is Advanced: you type “delete”, and it’s only offered for options that belong to an inactive plugin or theme, or to a plugin you removed. WordPress and WooCommerce options are never deleted, and values that look like secrets, such as API keys, stay masked until an admin reveals them.

Admin Powerups needs WordPress 6.7, WooCommerce 9.9 and PHP 8.1 or later. Every power-up is off until you switch it on under WooCommerce → Powerups, and one that’s off adds nothing to your store. The Database clean-up docs list every check with its badge, and the Autoloaded options docs explain each screen.

Keep reading