How to remove checkout fields in Woocommerce
A two step guide on how to remove checkout fields in Woocommerce programatically. Below I’m going to show you a safe and quick way to remove the checkout fields. Don’t worry if you make a mistake, you can easily undo the changes.
Step 1 – prerequisites
In case you have access to your themes functions.php file, create a backup of it as the first step. Please never use the theme editor in your WordPress dashboard, it will give you a lot of headaches.
If you don’t have access to the functions.php file, download a plugin like the My Custom Functions which gives you the ability to add custom PHP code to your website. For the beginners I recommend this option.
The default Woocommerce checkout fields are:
- billing first name (the Woocommerce system name is billing_first_name)
- billing last name (billing_last_name)
- billing company name (billing_company)
- billing country (billing_country)
- billing county/state (billing_state)
- billing postcode (billing_postcode)
- billing city (billing_city)
- billing street address -> 2 input fields (billing_address_1, billing_address_2)
- billing phone (billing_phone)
- billing email (billing_email)
- shipping first name (shipping_first_name)
- shipping last name (shipping_last_name)
- shipping company (shipping_company)
- shipping country (shipping_country)
- shipping county/state (shipping_state)
- shipping postcode (shipping_postcode)
- shipping city (shipping_city)
- shipping street address -> 2 input fields (shipping_address_1, shipping_address_2)
- order notes (order_comments)
Step 2 – removing the fields
To remove a field you will have to add a few lines of PHP code to the end of your functions.php file, or to the custom code editor of the plugin (for the My Custom Functions it will be Settings -> PHP Inserter from your dashboard). You can remove or change your checkout fields with the “woocommerce_checkout_fields” hook. For example you can remove the shipping company field like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/** ** Remove shipping company from checkout **/ add_action('woocommerce_checkout_fields', 'fdev_remove_shipping_company', 10, 1); function fdev_remove_shipping_company($checkout_fields){ /** ** Add your other fields below this comment **/ unset($checkout_fields['shipping']['shipping_company']); return $checkout_fields; } |
The method which removes every default checkout field from Woocommerce:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/** * Remove all checkout fields **/ add_action('woocommerce_checkout_fields', 'fdev_remove_all_checkout_fields', 10, 1); function fdev_remove_all_checkout_fields($checkout_fields){ /** * Billing fields **/ unset($checkout_fields['billing']['billing_first_name']); unset($checkout_fields['billing']['billing_last_name']); unset($checkout_fields['billing']['billing_company']); unset($checkout_fields['billing']['billing_address_1']); unset($checkout_fields['billing']['billing_address_2']); unset($checkout_fields['billing']['billing_city']); unset($checkout_fields['billing']['billing_postcode']); unset($checkout_fields['billing']['billing_country']); unset($checkout_fields['billing']['billing_state']); unset($checkout_fields['billing']['billing_phone']); unset($checkout_fields['billing']['billing_email']); /** * Shipping fields **/ unset($checkout_fields['shipping']['shipping_first_name']); unset($checkout_fields['shipping']['shipping_last_name']); unset($checkout_fields['shipping']['shipping_company']); unset($checkout_fields['shipping']['shipping_address_1']); unset($checkout_fields['shipping']['shipping_address_2']); unset($checkout_fields['shipping']['shipping_city']); unset($checkout_fields['shipping']['shipping_postcode']); unset($checkout_fields['shipping']['shipping_country']); unset($checkout_fields['shipping']['shipping_state']); unset($checkout_fields['order']['order_comments']); return $checkout_fields; } |
Change this method above according to your needs. For example if you would like to hide billing company, shipping company, billing state and shipping state from the Woocommerce checkout, leave the lines belonging to these fields and delete everything else:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/** * Remove all checkout fields **/ add_action('woocommerce_checkout_fields', 'fdev_remove_all_checkout_fields', 10, 1); function fdev_remove_all_checkout_fields($checkout_fields){ /** * Billing fields **/ unset($checkout_fields['billing']['billing_company']); unset($checkout_fields['billing']['billing_state']); /** * Shipping fields **/ unset($checkout_fields['shipping']['shipping_company']); unset($checkout_fields['shipping']['shipping_state']); return $checkout_fields; } |
In case you encounter any errors, just delete the code from your functions.php file (alternatively replace functions.php with your backup file), or remove the code from the Custom Functions plugin. Happy coding!