title: Filter shipping method based on custom checkout field at checkout page
body: <p>I am using Woocommerce WordPress plugin</p>
  
  <p>Added one custom field at checkout page, called - Address Type which is drop down contains 2 values. Business/Commercial and Residential</p>
  
  <p>I have total 3 shipping methods - International Flat Rate, Flat Rate, Free Shipping</p>
  
  <p>Now, condition that I want when end user select residential then and then they will get all 3 shipping methods but once user select a business option then hide/remove International Flat Rate and Flat Rate shipping methods (I mean show only Free Shipping).</p>
  
  <pre><code>add_filter( 'woocommerce_checkout_fields' , 'add_address_type_field' );
  function add_address_type_field( $fields ) {
  
   $address_type_field = array(
      'type'      =&gt; 'select',
      'label'     =&gt; __('Address Type', 'woocommerce'),
      'required'  =&gt; false,
      'class'     =&gt; array('address-field', 'form-row-wide', 'validate-addresstype'),
      'clear'     =&gt; true,
      'options'   =&gt; array(
                      'residential'   =&gt; 'Residential',
                      'business'      =&gt; 'Business/Commercial'
                      ),
   );
  
   $fields['billing']['billing_address_type']   = $address_type_field;
   $fields['shipping']['shipping_address_type'] = $address_type_field;
  
   return $fields;
  }
   add_filter('woocommerce_package_rates', 'display_shipping_method_based_on_state', 10, 2);
   if(!function_exists('display_shipping_method_based_on_state')) {
  function display_shipping_method_based_on_state($rates) {
      global $woocommerce;
      $state = WC()-&gt;customer-&gt;shipping_state;        
      $address_type = WC()-&gt;customer-&gt;shipping_address_type;        
      $free_shipping = $rates['free_shipping'];
      if($address_type == 'business')
      {
          $rates = array();
          $rates['free_shipping'] = $free_shipping;
      }
      return $rates;
  }
  }
  </code></pre>
  
  <p>This is my code that I am trying. Let me know where I am wrong?</p>
  
  <p>Thanks in advance!</p>