Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set WooCommerce cart expiration

I would like to erase the cart content when the woocommerce session expires. I can see there's a variable setting the time in class WC_Session_Handler, however when it expires, products does not get removed from cart (i guess it behaves like this by design,it's not an error).

So please tell me how can i set the session expiration time for woocommerce cart so, that cart content gets removed when it expires?

like image 358
kuzditomi Avatar asked Jul 23 '13 13:07

kuzditomi


People also ask

How long does the WooCommerce session last?

By default, WooCommerce session data is stored for 48 hours. This means that if a customer does not return to your site within 48 hours, their session data will be lost.


1 Answers

From what I can see, WooCommerce 2.0.20 has a scheduled maintenance job that runs twice/day that will remove any cart sessions from the WordPress options table. The default expiration time is set to 48 hours from the time the user first created the cart. I'm guessing your standard WordPress scheduling routines (and server cron/at jobs) will need to be running properly for this to execute.

AFAIK there is no way to adjust the 48 hour rule via settings. You could write a filter in your theme or in an "adjacent" plugin.

Here are some code fragments from a new "WooCommerce Extend Cart Timeout" plugin I built on my site:

Inside my WoocommerceLicenseAPI class:

if ( ! class_exists( 'WoocommerceLicenseAPI' ) ) {
add_filter('wc_session_expiring'   , array('WoocommerceLicenseAPI',       'filter_ExtendSessionExpiring') );

add_filter('wc_session_expiration' , array('WoocommerceLicenseAPI', 'filter_ExtendSessionExpired') );
{

static function filter_ExtendSessionExpiring($seconds) {
    return (60 * 60 * 24 * 8) - (60 * 60);
}
static function filter_ExtendSessionExpired($seconds) {
    return 60 * 60 * 24 * 8;
}

HTH

like image 164
Lance Cleveland Avatar answered Sep 19 '22 04:09

Lance Cleveland