title: Disable shipping method when a cart item has a specific shipping class?
body: <p>I try to disable a shipping method if a specific shipping class is in the cart. Im using the newest woocommerce version.</p>
  
  <p>Below is my Code for my task.
  Its placed at the end of my <code>functions.php</code> file of my Theme.</p>
  
  <p>Sadly its not working.</p>
  
  <pre><code>add_filter( 'woocommerce_package_rates', 'businessbloomer_hide_free_shipping_for_shipping_class', 10, 2 );
  function businessbloomer_hide_free_shipping_for_shipping_class( $rates, $package ) {
      $shipping_class_target = 513;           // ID OF MY SHIPPING_CLASS
      $in_cart = false;
      foreach( WC()-&gt;cart-&gt;cart_contents as $key =&gt; $values ) {
          if( $values[ 'data' ]-&gt;get_shipping_class_id() == $shipping_class_target ) {
              $in_cart = true;
              break;
          } 
      }
      if( $in_cart ) {
          unset( $rates['flat_rate:2'] );     //VALUE:ID OF MY SHIPPING METHOD
      }
      return $rates;
  }
  </code></pre>