title: Required Checkout Field Based on Shipping Method - Woocommerce
body: <p>I'd like to make <code>billing_last_name</code> not required if local pickup is chosen. </p>
  
  <p>Trying something like this:</p>
  
  <pre><code>function xa_remove_billing_checkout_fields($fields) {
      $shipping_method ='local_pickup'; // Set the desired shipping method to hide the checkout field(s).
      global $woocommerce;
      $chosen_methods = WC()-&gt;session-&gt;get( 'chosen_shipping_methods' );
      $chosen_shipping = $chosen_methods[0];
  
      if ($chosen_shipping == $shipping_method) {
         $fields['billing']['billing_last_name'][ 'required' ] = false;
      }
      return $fields;
  }
  </code></pre>
  
  <p>But it's not working. </p>
  
  <p>Is there a proper solution?</p>