woocommerce remove fields from order checkout 1

How to remove fields from checkout & ordering form in WooCommerce

Davor 03/08/2020

WooCommerce is definitely a great piece of e-commerce platform and comes packed with lots of extra features. However, sometimes you might need to remove or edit some of the form items on the checkout page, cart page, and ordering page.

The options to remove or alter the fields and label is not included in the default WooCommerce feature set. But, luckily there is a workaround for everything. 😉

Remove or unset field in WooCommerce

As the Woocommerce documentation states,  billing and shipping fields for checkout as pulling from countries class (class-wc-countries.php) and theget_address_fields function. So, the WooCommerce allows us to filter and enable/disable any form.

Before the WooCommerce returns the value of this form fields, it puts the fields through a filter.

And, this is where our code comes to play. 😉

In order to remove some fields from the form, open up the functions.php of your child theme and add this code.

add_filter( 'woocommerce_checkout_fields' , 'worda_override_checkout_fields' );

function worda_override_checkout_fields( $fields ) {
     unset($fields['billing']['billing_city']);
     unset($fields['billing']['billing_postcode']);
     unset($fields['billing']['billing_company']);
     unset($fields['shipping']['shipping_city']);
     unset($fields['shipping']['shipping_postcode']);
     unset($fields['shipping']['shipping_address_2']);
     unset($fields['shipping']['shipping_company']);
     
     return $fields;
}

You should notice that we use the “unset” to remove and deregister the fields from the pages with ordering form.

Basically, there are 4 groups of form fields used in WooCommerce checkout and order pages. Those are Billing, Shipping, Account, and Order.

As for our example code above, the first 3 options are assigned as the “billing” group. It will remove the field from the billing part of the form. The second 4 lines demonstrate options to unset the form field, are under the “shipping” group.

Now, just replace the example code unset options values to some of the form values you really want to remove. You can refer to the list of all form fields values below.

List of fields in WooCommerce checkout & order forms

You can see the entire list of fields in the array passed to “woocommerce_checkout_fields”:

  • Billing
    • billing_first_name
    • billing_last_name
    • billing_company
    • billing_address_1
    • billing_address_2
    • billing_city
    • billing_postcode
    • billing_country
    • billing_state
    • billing_email
    • billing_phone
  • Shipping
    • shipping_first_name
    • shipping_last_name
    • shipping_company
    • shipping_address_1
    • shipping_address_2
    • shipping_city
    • shipping_postcode
    • shipping_country
    • shipping_state
  • Account
    • account_username
    • account_password
    • account_password-2
  • Order
    • order_comments

You can use any of the forms elements names and remove them from the forms in desired locations from the above list.

Conclusion

It should be easy to figure out which field from the list you want to remove. Then just use it as the property in the code of the above-mentioned function.

 

Davor Veselinović

I'm Davor, founder of Worda Themes. Working as a Full Stack Developer with more than a decade of experience with WordPress. I build themes and plugins and enjoy writing useful blog posts and share my ideas with others.

Leave a Reply

Your email address will not be published. Required fields are marked *