wordpress - Building a 'case' of beer bottles in WooCommerce mini-cart.php template -


really trying nail issue can't quite complete. i've raised query reckon unclear little clearer here.

i have amended mini-cart display different image every item added cart. simulate adding of bottles 'case'. see image show in action, , here code makes work.

<?php  if(wc()->cart->get_cart_contents_count() == 0){     echo '<img src="http://example.com/wp-content/uploads/2017/…/empty-case.png" alt="icon" />'; } elseif (wc()->cart->get_cart_contents_count() == 1){     echo '<img src="http://example.com/…/uploads/2017/06/case-with-1-bottle.png" alt="icon" />'; elseif (wc()->cart->get_cart_contents_count() == 2){     echo '<img src="http://example.com/…/uploa…/2017/06/case-with-2-bottles.png" alt="icon" />'; 

this continues until 60 bottles or so, , works fine.

the problem is, it's based on cart total, , there other items in shop don't want include within this. i want 'single bottles' product category, not 't-shirts' (for example).

ideally, i'd love add exclude other categories i'm unsure needs done.

any ideas or suggestions?

mini cart bottle case

you can make calculation product category "single bottles", way:

<?php     // set here product category     $category = 'single bottles';      $beer_count = 0;      foreach ( wc()->cart->get_cart() $cart_item ){         if( has_term( $category, 'product_cat', $cart_item['data']->get_id() ) ){             $beer_count += $cart_item['quantity'];         }     }      if ( $beer_count == 0 ) {         echo '<img src="http://example.com/wp-content/uploads/2017/…/empty-case.png" alt="icon" />';     } elseif ( $beer_count == 1 ) {         echo '<img src="http://example.com/…/uploads/2017/06/case-with-1-bottle.png" alt="icon" />';     } elseif ( $beer_count == 2 ) {         echo '<img src="http://example.com/…/uploa…/2017/06/case-with-2-bottles.png" alt="icon" />';     } 

this should work…


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -