2017-02-20 62 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> 
相关问题