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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.