title: Hide shipping methods for specific shipping class in WooCommerce
body: <p>Essentially I'm trying to make the flat rate method Id <code>flat_rate:7</code> <strong>disabled</strong> when there is cart items that have the shipping class "Roller" (ID <code>92</code>).</p>
  
  <p><strong>This is the code I tried:</strong></p>
  
  <pre><code>add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_based_on_shipping_class', 10, 2);
  
  function wf_hide_shipping_method_based_on_shipping_class($available_shipping_methods, $package)
  {
      $hide_when_shipping_class_exist = array(
          92 =&gt; array(
              'flat_rate:7'
          )
      );
  
      $shipping_class_in_cart = array();
      foreach(WC()-&gt;cart-&gt;cart_contents as $key =&gt; $values) {
         $shipping_class_in_cart[] = $values['data']-&gt;get_shipping_class_id();
      }
  
      foreach($hide_when_shipping_class_exist as $class_id =&gt; $methods) {
          if(in_array($class_id, $shipping_class_in_cart)){
              foreach($methods as &amp; $current_method) {
                  unset($available_shipping_methods[$current_method]);
              }
          }
      }
  
      return $available_shipping_methods;
  }
  </code></pre>
  
  <p>Shipping class ID <strong><code>92</code></strong> is the shipping class and I want to hide <code>flat_rate:7</code> for it.</p>
  
  <p>My Site is this: <a href="http://www.minimoto.me/" rel="nofollow noreferrer">http://www.minimoto.me/</a>
  WordPress: 4.8.4
  WooCommerce: 3.1.1</p>
  
  <p>Any help will be greatly appreciated.</p>