title: Remove duplicated shipping packages using a shipping class in Woocommerce
body: <p>The products in my website are handled by one of that 2 shipping plugins: <a href="https://wordpress.org/plugins/printful-shipping-for-woocommerce/" rel="nofollow noreferrer">Printful Integration for WooCommerce</a> and <a href="https://wordpress.org/plugins/printify-for-woocommerce/" rel="nofollow noreferrer">Printify for WooCommerce Shipping</a>. when there is mixed items from each shipping plugin. Those plugins split each one the shipping package in two when there is mixed items <em>(which is a a conflict and a problem)</em>. </p>
  
  <p>So I have added a shipping class <strong><code>'printful'</code></strong> <em>(which id is <strong><code>548</code></strong>)</em> to the products that are handled by the <a href="https://wordpress.org/plugins/printful-shipping-for-woocommerce/" rel="nofollow noreferrer">Printful plugin</a>, and tried to adjust <a href="https://stackoverflow.com/questions/47718180/hide-shipping-method-for-specific-shipping-classes-in-woocommerce/47732732#47732732">Hide shipping method for specific shipping classes in woocommerce</a> answer code by @LoicTheAzec (cheers), to only remove the shipping method from a specific duplicated shipping packages with ids 2 and 3 due to the conflict between the shipping plugins…</p>
  
  <p><a href="https://i.stack.imgur.com/7ySV1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ySV1.png" alt="enter image description here"></a></p>
  
  <p>Here is my actual code:</p>
  
  <pre><code>    add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
  function hide_shipping_method_based_on_shipping_class( $rates, $package )
  {
      if ( is_admin() &amp;&amp; ! defined( 'DOING_AJAX' ) )
          return;
  
      // HERE define your shipping class to find
      $class = 548; //CAMDEN HARBOR CHART MUG is in shipping class
  
      // HERE define the shipping methods you want to hide
      $method_key_ids = array('printify_shipping_s', 'printify_shipping_e');
  
      // 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_id() == $class ){
              foreach( $method_key_ids as $method_key_id ){
  
                  unset($rates[$method_key_id]); // Remove the targeted methods
              }
              break; // Stop the loop
          }
      }
      return $rates;
  }
  </code></pre>
  
  <p>But it's not working and I still get 4 shipping packages instead of two:</p>
  
  <p><a href="https://i.imgur.com/L0mnkVO.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/L0mnkVO.png" alt="enter image description here"></a></p>
  
  <p>Any help is appreciated.</p>