WooCommerce Shipping – Hide checkout fields based on shipping method

In many cases, you don’t want to display all the default checkout fields in WooCommerce. For example, many shop owners often prefer not to show the Billing Address field.

Using the below code snippet, one can easily hide any checkout field when a particular shipping method is selected.

Just copy and paste the snippet in Appearance –>Editor –> functions.php and you are done!

As we can see, in the above snippet, on selecting “Free Shipping” as a shipping method in the cart page, Billing address 1 and 2 are hidden from the checkout page. This can be validated from the screenshot shown below:


Comments (9)

  • blasinhogm
    blasinhogm

    Good evening, I am trying to use your method but it does not work for me at any time, this version designed in the concrete version of woocommerce? I want to do it with a local environment, without free shipping, but I do not understand why you put free_shipping:1, the number 1 where it comes from?

    Greetings and thanks

    September 12, 2018 at 4:56 am
    • Anindo
      Anindo

      Hi,

      This snippet is designed to hide checkout fields based on the ‘Shipping method’ value(free_sipping:1 is the value of that method). You can get the shipping method value by inspecting a shipping method.
      – Select a shipping method –> Right Click–> Inspect–> You can see the ‘Value’ of that method.

      September 12, 2018 at 4:20 pm
  • justin_e2014
    justin_e2014

    hey. how can you make it so you dont have to refresh the page when switching shipping methods

    September 4, 2018 at 12:57 pm
    • Anindo
      Anindo

      Hi Justin,

      Once the hipping method is selected the values will be shown based on this Method. However, when you switch to any other method, WooCommerce will show the previously cached values. Hence, in order to avoid displaying cached values, you would need to refresh the page.

      September 4, 2018 at 6:07 pm
  • carinlockhart
    carinlockhart

    I am trying to get this to work when using the table rate plug-in. I want to hide the shipping address if the following is true:

    I have been trying it by setting my shipping_method=’table_rate:10:1′, but that is clearly not right. Ideas?

    August 16, 2018 at 2:00 am
    • Anindo
      Anindo

      Hi @carin,

      This snippet will hide only specific fields of Billing address.
      However, you do have an option to change the default shipping destination fields in WooCommerce shipping options.
      WooCommerce–> Shipping Options–> Shipping Destination –> (select) Default to customer billing address.

      Once done, “Ship to a different address” will not checked by default.
      Hope that helps!

      August 17, 2018 at 6:30 pm
  • jsotnas
    jsotnas

    Thank you Anindo for the reply.

    Hiding in checkout a custom_field based on ‘Payment method’ is tricky? 🙁

    Ho good!

    Regards,

    July 5, 2018 at 6:27 pm
  • jsotnas
    jsotnas

    Great tutorial!

    thanks.

    But how can i hide field based on gateway choice?

    $payment_method instead of #shipping_method ???

    July 5, 2018 at 12:11 am
    • Anindo
      Anindo

      Hi,

      This snippet is designed to hide checkout fields based on ‘Shipping method’ only.
      Also it would not be practically possible to hide any checkout fields based on ‘Payment method’. This is because, you will be directed to ‘Payment method’ only after you complete the initial process of filing in checkout fields.
      Hence, hiding checkout fields based on ‘Payment method’ is quite tricky to acheive.

      Regards,

      July 5, 2018 at 4:21 pm

Leave a Reply