且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

即使已登录的用户也清除页面加载中的Woocommerce购物车

更新时间:2023-09-10 17:12:40

已更新并得到增强.

使用Woocommerce条件标签,并尝试使用 template_redirect 钩子代替(当购物车不为空时):

Use Woocommerce conditional tags and try template_redirect hook instead (when cart is not empty):

add_action( 'template_redirect', 'custom_empty_cart' );
function custom_empty_cart() {
    if ( ! ( is_cart() || is_checkout() ) && ! WC()->cart->is_empty() ) {
        WC()->cart->empty_cart( true );
}

代码在您的活动子主题(或活动主题)的function.php文件上.应该可以.

Code goes on function.php file of your active child theme (or active theme). It should work.