title: Different shipping classes
body: <p>I have a website where I need to charge different delivery fees for different products.
  The standard delivery fee is $50 per order irrelevant of how many items.</p>
  <p>However, I have some bulky orders where I will need to charge $150 for them and up to 2 items. So let's say if you buy 2 bulky items, the delivery charge would be $150 but if you buy 3 it would go up to $300 and so on.</p>
  <p>When the client puts items in the cart, they will be charged for bulky items and regular items separately, so if the customer puts 1 bulky item and 1 normal item, they need to be charged $150 + $50 which makes the delivery fee $200 in total.</p>
  <p>I tried to create a shipping class for the bulky items and in the settings, I have configured it as below:</p>
  <p><a href="https://i.stack.imgur.com/LbBLv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LbBLv.png" alt="enter image description here" /></a></p>
  <p>I also have this logic in my functions file which takes care of charging in multiples in case of heavy products:</p>
  <pre><code>add_filter( 'woocommerce_package_rates', 'different_rates_based_on_quantity_steps', 10, 2 );
  function different_rates_based_on_quantity_steps ( $rates, $package ){
  
  $slug_class_shipping = 'test'; // Slug of the shipping class
  $step_change = 2; // Steps for item
  $item_count = 0;
  
  // Checking in cart items
  foreach( WC()-&gt;cart-&gt;get_cart() as $cart_item ){
  
      // If we find the shipping class
      if( $cart_item['data']-&gt;get_shipping_class() == $slug_class_shipping ){
  
          $item_count += $cart_item['quantity']; // Cart item count
          $rate_operand = ceil( $item_count / $step_change ); // Operand increase each # items here
  
          foreach ( $rates as $rate_key =&gt; $rate ){
              // Targetting &quot;Flat rate&quot;
              if( 'flat_rate' === $rate-&gt;method_id ) {
                  $has_taxes = false;
  
                  // Set the new cost
                  $rates[$rate_key]-&gt;cost = $rate-&gt;cost * $rate_operand;
  
                  // Taxes rate cost (if enabled)
                  foreach ($rates[$rate_key]-&gt;taxes as $key =&gt; $tax){
                      if( $tax &gt; 0 ){
                          // New tax calculated cost
                          $taxes[$key] = $tax * $rate_operand;
                          $has_taxes = true;
                      }
                  }
                  // Set new taxes cost
                  if( $has_taxes )
                      $rates[$rate_key]-&gt;taxes = $taxes;
              }
           }    
           return $rates;
        } 
        break; 
     }
  }  
  </code></pre>
  <p>That said, unfortunately, this is not working as expected.<br />
  If I add 2 bulky items, this is calculating the delivery fee at $200 (instead of $150), and if I add regular items the delivery fee doesn't change and remains at $200.</p>
  <p>If I add 3 bulky items, delivery is totalling $400 (instead of $300) and if I add 5 it is going up to $600 (instead of $450).  It is like always adding the base fee in case of bulky items, but not adding it in case of regular ones.</p>
  <p>Can someone help me with what I'm doing wrong?</p>