# Keep Guest Carts for a Week

> Extends how long a guest's cart is remembered from two days to seven, so visitors who come back later still find their products waiting.

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

## Code

```php
$wpide_cart_days = 7; // Days to keep guest sessions.

add_filter( 'wc_session_expiration', function () use ( $wpide_cart_days ) {
    return $wpide_cart_days * DAY_IN_SECONDS;
} );

add_filter( 'wc_session_expiring', function () use ( $wpide_cart_days ) {
    return ( $wpide_cart_days * DAY_IN_SECONDS ) - HOUR_IN_SECONDS;
} );
```

## Notes

Longer sessions mean more rows in the woocommerce_sessions table; WooCommerce cleans expired ones daily.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep Guest Carts for a Week" 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/
