设置WooCommerce购物车到期 [英] Set WooCommerce cart expiration

查看:140
本文介绍了设置WooCommerce购物车到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在woocommerce会话期满时删除购物车中的内容. 我可以看到在类 WC_Session_Handler 中有一个设置时间的变量,但是当它过期时,产品不会从购物车中移除(我猜它的行为是设计使然,这不是错误).

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).

所以请告诉我如何设置woocommerce购物车的会话过期时间,以便购物车内容在过期时被删除?

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

推荐答案

据我所知,WooCommerce 2.0.20的计划维护工作每天运行两次,它将从WordPress选项表中删除所有购物车会话.从用户首次创建购物车开始,默认的过期时间设置为48小时.我猜想您的标准WordPress调度例程(和服务器cron/at作业)将需要正确运行才能执行.

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无法通过设置来调整48小时规则.您可以在主题或相邻"插件中编写过滤器.

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.

以下是我在网站上构建的新"WooCommerce扩展购物车超时"插件中的一些代码片段:

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

在我的WoocommerceLicenseAPI类中:

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

这篇关于设置WooCommerce购物车到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆