title: Max item quantity added to cart based on product category in Woocommerce
body: <p>I am trying to customize the shop such that Category named Quantity4 allows only 4 items to be added in the cart and category named Quantity6 allows only items to be added in the cart.</p>
  
  <p>As far as I can get, this can be achieved using nested <code>if</code> statements, but somehow this doesn't work.</p>
  
  <pre><code>add_filter( 'woocommerce_add_to_cart_validation', 'only_four_items_allowed_add_to_cart', 10, 3 );
  
  function only_four_items_allowed_add_to_cart( $passed, $product_id, $quantity ) {
  
  $cart_items_count = WC()-&gt;cart-&gt;get_cart_contents_count();
  $total_count = $cart_items_count + $quantity;
  
  if(has_term('quantity4','product_cat',$product_id )){
  if($cart_items_count &gt;= 4 || $total_count &gt; 4){
          // Set to false
          $passed = false;
          // Display a message
          wc_add_notice( __( "You Chose a Box of 4 Items, Can't Add More", "woocommerce" ), "error" );
      }
    }
  
    else if (has_term('quantity6','product_cat',$product_id )){
      if($cart_items_count &gt;= 6 || $total_count &gt; 6){
          // Set to false
          $passed = false;
          // Display a message
          wc_add_notice( __( "You Chose a Box of 6 Items, Can't Add More", "woocommerce" ), "error" );
      }
  }
  
  return $passed;
  }
  </code></pre>
  
  <p>Can someone pls point out what am I doing wrong here and how to get the desired results.</p>