Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
472 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...