我想知道如何使用WooCommerce在页面加载时清空购物车中的内容。
我发现可以通过在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();
}
}
但我想知道如何在主页加载时触发它(如果您可以指定确切的页面,那将非常好,但即使是主页也很有用)
有什么想法吗?谢谢!
$woocommerce->cart->empty_cart();
。 - codacopia$woocommerce->cart->empty_cart();
替换为更新版本的WC()->cart->empty_cart();
。 - João Teixeiraadd_action('woocommerce_after_cart_table', [$this, 'add_empty_cart_button_to_cart']); public function add_empty_cart_button_to_cart() { ob_start(); ?> 清空购物车
- Morten Bak