2017-02-20 9 views
2

ミニカートの商品数に含めたくない商品があります。商品をWooCommerceカートに入れないでください

これは私がこのミニカート出力に使用するコード数:

 <span class="cart-quantity"> 
     <?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'organica'), $woocommerce->cart->cart_contents_count);?> 
    </span> 

は、どのように私は数えるこのミニカートの項目に特定の製品のIDが含まれていないために何ができますか?ここで

おかげ

答えて

1

は、あなたが以下のコメントコードで設定する必要があること、特定の製品IDに関連する項目をカウントせずに、このカートの数を達成するための方法である:

<?php 

    // HERE set the product ID that hasn't to be counted 
    $product_not = 28; 

    // Initializing the count 
    $cart_items_count = 0; 

    // Iterating through each items in cart 
    foreach(WC()->cart->get_cart() as $cart_item){ 
     if($cart_item['product_id'] != $product_not) 
      $cart_items_count++; 
    } 

?> 

    <span class="cart-quantity"> 
     <?php echo sprintf(_n('%d', '%d', $cart_items_count, 'organica'), $cart_items_count);?> 
    </span> 
関連する問題