Woocommerce 清空购物车并在特定页面模板上添加新产品
我想在添加新产品之前清空购物车,它可以使用以下代码:
add_filter( 'woocommerce_add_cart_item_data', 'wdm_empty_cart', 10, 3);
function wdm_empty_cart( $cart_item_data, $product_id, $variation_id ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return $cart_item_data;
}
现在我需要在特定的页面模板上执行此操作。这可能吗?
我试过了,但没用
add_filter( 'woocommerce_add_cart_item_data', 'wdm_empty_cart', 10, 3);
function wdm_empty_cart( $cart_item_data, $product_id, $variation_id ) {
global $woocommerce;
if (is_page_template('templates/checkout.php')){
$woocommerce->cart->empty_cart();
}
return $cart_item_data;
}
I want to empty the cart before adding a new product and it works with this code:
add_filter( 'woocommerce_add_cart_item_data', 'wdm_empty_cart', 10, 3);
function wdm_empty_cart( $cart_item_data, $product_id, $variation_id ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return $cart_item_data;
}
Now I need to do this on a specific page template. Is that possible?
I tried this but it's not working
add_filter( 'woocommerce_add_cart_item_data', 'wdm_empty_cart', 10, 3);
function wdm_empty_cart( $cart_item_data, $product_id, $variation_id ) {
global $woocommerce;
if (is_page_template('templates/checkout.php')){
$woocommerce->cart->empty_cart();
}
return $cart_item_data;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论