title: Woocommerce, hide shipping method based on shipping class
body: <p>I'm trying to hide all but one shipping method based on the shipping class, essentially forcing the FedEx overnight method when a product belonging to a specific class is selected.</p>
  
  <p>I'm starting with <a href="https://stackoverflow.com/questions/17409112/hide-shipping-options-woocommerce">this code</a>, and modifying it as indicated below: </p>
  
  <pre><code>add_filter( 'woocommerce_available_shipping_methods', 'hide_shipping_based_on_class' ,    10, 1 );
  
  function check_cart_for_share() {
  
  // load the contents of the cart into an array.
  global $woocommerce;
  $cart = $woocommerce-&gt;cart-&gt;cart_contents;
  
  $found = false;
  
  // loop through the array looking for the tag you set. Switch to true if the tag is     found.
  foreach ($cart as $array_item) {
  $term_list = wp_get_post_terms( $array_item['product_id'], 'product_shipping_class', array( "fields" =&gt; "names" ) );
  
  if (in_array("Frozen",$term_list)) {
  
        $found = true;
        break;
      }
  }
  
  return $found;
  
  }
  
  function hide_shipping_based_on_class( $available_methods ) {
  
  // use the function above to check the cart for the tag.
  if ( check_cart_for_share() ) {
  
  // remove the rate you want
  unset( $available_methods['canada_post,purolator,fedex:FEDEX_GROUND,fedex:GOUND_HOME_DELIVERY'] ); 
  }
  
  // return the available methods without the one you unset.
  return $available_methods;
  
  }
  </code></pre>
  
  <p>It doesn't seem to be hiding any shipping methods though. Not sure what I'm missing...</p>
  
  <p>It's a multi-site installation, I'm testing it on the Canadian side at <a href="http://stjeans.harbourcitydevelopment.com" rel="nofollow noreferrer">http://stjeans.harbourcitydevelopment.com</a></p>
  
  <p>I'm running the Table Rate shipping module, as well as the FedEx, Purolator and Canada Post modules.</p>