2016-04-21 170 views

回答

1

找到了解決辦法。不知道爲什麼這與我嘗試過的其他解決方案相比,但它的工作原理!

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; 

//Check if product ID is in a certain category 
if(has_term('category-slug', 'product_cat', $product_id)){ 

    $woocommerce->cart->empty_cart(); 
} 

//Do nothing with the data and return 
return $cart_item_data; 

} 
相關問題