我的函数中包含以下代码,以允许我们通过网址清空购物车:
// check for clear-cart get param to clear the cart, append ?clear-cart to any site url to trigger this
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
这似乎仅适用于woocommerce页面(购物车,商店等) 用户转到https://example.com?clear-cart时似乎不会触发。