カートおよびチェックアウトページにカートのアイテムを削除するには、私はカートおよびチェックアウトページのフックでカスタムフック機能、この方法を使用します。
add_action('woocommerce_before_cart', 'removing_the_free_cart_items');
add_action('woocommerce_before_checkout_form', 'removing_the_free_cart_items');
function removing_the_free_cart_items() {
if (!WC()->cart->is_empty()):
// Here your free products IDs
$free_products = array(10,52,63,85);
// iterating throught each cart item
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item){
$cart_item_id = $cart_item['data']->id;
// If free product is in cart, it's removed
if(in_array($cart_item_id, $free_products))
WC()->cart->remove_cart_item($cart_item_key);
}
endif;
}
をこのコードは、function.phpに行きますあなたのアクティブな子供のテーマ(またはテーマ)のファイル、またはすべてのプラグインファイル。
このコードはテスト済みであり、動作します。
ありがとうございます@LoicTheAztec – mysticalghoul