如何清除Woocommerce购物车 [英] How to clear a Woocommerce cart

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

问题描述

我想知道如何使用woocommerce在页面加载时清除购物车中的内容。

I am wondering how you can clear the contents of your cart on page load using woocommerce.

我遇到了如何通过添加此按钮来添加清除购物车按钮的方法进入functions.php

I came accross how to add a clear cart button using by adding this in to functions.php

add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
  global $woocommerce;

    if ( isset( $_GET['empty-cart'] ) ) {
        $woocommerce->cart->empty_cart(); 
    }
}

但我想知道如何触发这就是说,主页的页面加载量(如果您可以指定确切的页面会很棒,但是即使主页也会有用)

But I was wondering how I'd go about triggering this on say, page load of the home page (if you could specifiy the exact page that would be great, but even the home page would be useful)

有什么想法吗?谢谢!

推荐答案

其更新版本为:

WC()->cart->empty_cart();

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

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