WooCommerce is a very powerful eCommerce plugin. No Doubt WooCommerce’s default checkout page is great. But there are times when you need to customize the checkout fields. Imagine you have a digital product store, then you probably need only the First Name, Last Name, and Email. Unfortunately, WooCommerce doesn’t provide the option to remove these fields.
But, they can be removed using custom code. This post will help you to understand how to remove unwanted fields with custom code safely. I have also incorporated a tutorial to make the task easy.
Just for the records, I am using Astra Theme ( The Fastest, Flexible and Free theme for WordPress ) in my tutorial.
How to safely add custom code?
You can add custom code to the site in several ways. Eg. Using child theme’s functions.php, Using a custom plugin, using FTP to edit files, etc. You can pick any method you are familiar with.
I will show how to add custom code without directly editing a functions.php file. I will suggest a plugin Code Snippets. It will allow adding custom code quickly and, most importantly, safely. This plugin will run your code without a fatal error, that means your website will not break even if you have an error in your code. The custom code will work even after you switch the theme.
Let’s get started:
How to remove Billing Fields?
Available Billing Fields:
- billing_first_name
- billing_last_name
- billing_company
- billing_address_1
- billing_address_2
- billing_city
- billing_postcode
- billing_country
- billing_state
- billing_phone
- billing_email
Available Additional Field:
- order_comments
The code from below gist will remove all billing and additional fields form the checkout page.
/**
* @snippet WooCommerce How To Remove Checkout Fields @ Checkout Page
* @author Sandesh Jangam
* @donate $7 https://www.paypal.me/SandeshJangam/7
*/
add_filter( 'woocommerce_checkout_fields' , 'ts_custom_remove_checkout_fields' );
function ts_custom_remove_checkout_fields( $fields ) {
/* Billing Field */
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_postcode'] );
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_state'] );
unset( $fields['billing']['billing_phone'] );
unset( $fields['billing']['billing_email'] );
/* Additional Filed */
unset( $fields['order']['order_comments'] );
return $fields;
}
Just take a look at a code. You will easily understand the name of each field.
For example, if you want to remove company, address 1, and address 2 fields then just keep this below field in code ( keep lines 10, 11, 12 and remove other field lines )
- billing_company
- billing_address_1
- billing_address_2
Refer this example for details.
/**
* @snippet WooCommerce How To Remove Checkout Fields @ Checkout Page
* @author Sandesh Jangam
* @donate $7 https://www.paypal.me/SandeshJangam/7
*/
add_filter( 'woocommerce_checkout_fields' , 'ts_custom_remove_checkout_fields' );
function ts_custom_remove_checkout_fields( $fields ) {
/* Billing Field */
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
return $fields;
}
If you would like to display any checkout fields that have been removed, you can simply delete that line from code which represents that specific field.
That’s it!
If you find any difficulty while using the custom code, please feel free to add your thought in the comments below. I Will love to hear back 🙂