title: Hide checkout shipping fields section for specific shipping method in WooCommerce
body: <p>Someone asked the following question that I have answered. Then he delete it. So I publish the question and my answer back as this can be useful for the community:</p>
  
  <p>In WooCommerce, I am trying to update a checkbox form dynamically without reloading the checkout page.
  I have 2 shipping methods: "Delivery" and "Collect". I am trying to only disable the shipping address section <em>(with the "ship to another address if chosen method is collect" checkbox option)</em> and all shipping fields.</p>
  
  <p>First I tried this:</p>
  
  <pre><code>add_action( 'woocommerce_after_shipping_rate', 'carrier_custom_fields', 30, 2 );
  function carrier_custom_fields( $method, $index ) {
      if( ! is_checkout()) return; // Only on checkout page
  
      $customer_carrier_method = 'local_pickup:1';
  
  
      if( $method-&gt;id != $customer_carrier_method ) return; // Only display for "local_pickup"
  
      $chosen_method_id = WC()-&gt;session-&gt;chosen_shipping_methods[ $index ];
  
      // echo $chosen_method_id;
  
      // If the chosen shipping method is 'legacy_local_pickup' we display
      if($chosen_method_id == $customer_carrier_method ):
  
          add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
  
      else :
          add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true');
  
  
      endif;
  
  }
  </code></pre>
  
  <p>Then I tried this:</p>
  
  <pre><code>add_action( 'woocommerce_shipping_method_chosen', 'check_if_local_pickup', 10, 1 );
  function check_if_local_pickup( $chosen_method ) {
      $chosen_methods = WC()-&gt;session-&gt;get( 'chosen_shipping_methods' );
      $chosen_shipping = $chosen_methods[0]; 
      if ($chosen_shipping == 'local_pickup:1') { 
          add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );
          add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
          return true;
      }
      else
      {
          add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true');
          return true;
  
      }
  } 
  </code></pre>
  
  <p>Both of them doesn't work. </p>
  
  <p>How to hide checkout shipping fields section for specific chosen shipping method in WooCommerce?</p>