# Shorter WooCommerce Guest Sessions

> Makes WooCommerce forget guest shopping sessions (cart contents and entered details) after 24 hours instead of two days, so less customer data sits in the sessions table.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Requires: WooCommerce
- Tags: woocommerce, sessions, retention
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-woo-shorter-sessions/

## Code

```php
// Hours a guest session lasts.
$wpide_wc_session_hours = 24;

add_filter( 'wc_session_expiration', function () use ( $wpide_wc_session_hours ) {
    return (int) $wpide_wc_session_hours * HOUR_IN_SECONDS;
} );

add_filter( 'wc_session_expiring', function () use ( $wpide_wc_session_hours ) {
    return max( 1, (int) $wpide_wc_session_hours - 1 ) * HOUR_IN_SECONDS;
} );
```

## Notes

Carts of guests who come back after more than a day will be empty.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Shorter WooCommerce Guest Sessions" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
