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

查看:51
本文介绍了设置 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 Extend Cart Timeout"插件的一些代码片段:

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天全站免登陆