The session expiration and the cart expiration are linked: they both use the same internal variable (a protected property of class WC_Session_Handler
, $_session_expiration
).
You can’t change one and not the other.
Removing the cart from the database is done by WC_Session_Handler->cleanup_sessions()
. This is invoked by the function wc_cleanup_session_data()
which is triggered by the woocommerce_cleanup_sessions
action .
You might try to remove the default action and provide your own.
remove_action( 'woocommerce_cleanup_sessions', 'wc_cleanup_session_data' );
function my_cleanup_sessions()
{
global $wpdb;
$wpdb->query( $wpdb->prepare( "DELETE FROM $this->_table WHERE session_expiry < %d", time() + 180 * 24 * 60 * 60 ) );
if ( class_exists( 'WC_Cache_Helper' ) ) {
WC_Cache_Helper::incr_cache_prefix( WC_SESSION_CACHE_GROUP );
}
}
add_action( 'woocommerce_cleanup_sessions', 'my_cleanup_sessions' );
I have not tested this. It might not work and there might be side effects.