Remove Address Fields in WooCommerce Billing and Shipping in Form Checkout

WooCommerce has the ability to remove the address fields in the checkout form of the billing and shipping forms, this is great if you do not require the address fields as you may have a virtual/download only products that don’t require shipping, less fields to fill out = happy customers.

woocommerce-all-address-fields

You can remove address field layouts, so you have just name and email.

woocommerce-all-name-email-fields

Remove Billing Fields

This is all done with the woocommerce_billing_fields filter, so in your themes functions.php you can add the following…

<?php
add_filter('woocommerce_billing_fields','wpb_custom_billing_fields');
// remove some fields from billing form
// ref - https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
function wpb_custom_billing_fields( $fields = array() ) {
unset($fields['billing_company']);
unset($fields['billing_address_1']);
unset($fields['billing_address_2']);
unset($fields['billing_state']);
unset($fields['billing_city']);
unset($fields['billing_phone']);
unset($fields['billing_postcode']);
unset($fields['billing_country']);
return $fields;
}
view raw remove-fields.php hosted with ❤ by GitHub

So this will remove or unset all the billing address fields if you want to keep a certain field in just remove the relevant line from the code snippet.

Remove Shipping Fields

If you have products that are linked to shipping, then the additional shipping fields also show, the woocommerce_shipping_fields filter can remove these, you probably want to keep most to ship the item, but might want to remove the shipping_company field for example.

<?php
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields_ek', 99 );
// Remove some fields from billing form
// Our hooked in function - $fields is passed via the filter!
// Get all the fields - https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
function custom_override_checkout_fields_ek( $fields ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
return $fields;
}
view raw remove-fields2.php hosted with ❤ by GitHub

What if you wanted to retain all the fields if the cart products contained shipped products but also wanted a trimmed down field selection if the cart only had virtual products – then you can use the looped carts items to determine if they are virtual only…

<?php
add_filter( 'woocommerce_checkout_fields' , 'virtual_products_less_fields' );
/**
* WooCommerce Remove Address Fields from checkout based on presence of virtual products in cart
* @link https://www.skyverge.com/blog/checking-woocommerce-cart-contains-product-category/
* @link https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
* @link https://businessbloomer.com/woocommerce-hide-checkout-billing-fields-if-virtual-product-cart/
*/
function virtual_products_less_fields( $fields ) {
// set our flag to be true until we find a product that isn't virtual
$virtual_products = true;
// loop through our cart
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products and if so make it false
if ( ! $cart_item['data']->is_virtual() ) $virtual_products = false;
}
// only unset fields if virtual_products is true so we have no physical products in the cart
if( $virtual_products===true) {
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']);
//Removes Additional Info title and Order Notes
add_filter( 'woocommerce_enable_order_notes_field', '__return_false',9999 );
}
return $fields;
}

Ref. & Ref

6 Comments

  1. hardik thakkar on April 30, 2019 at 4:25 am

    How can I do the opposite? When typing the address for some countries like Singapore, WooCommerce by default hides delivery suburb and state fields. Is there a way I can force those fields to be always visible?

  2. SuziQue on March 21, 2019 at 5:54 pm

    Is there a way to select for each product where or not an address is needed.
    I have both physical and digital products. I only need the address if they are ordering physical products.

    • Neil Gowran on March 23, 2019 at 12:18 am

      Good question – have added a snippet in the post.

  3. Patryk on March 13, 2019 at 9:08 am

    Is there possibility to set fields dependently on user role?
    In. example I have basic user and merchendiser
    For basic user I don’t need address, only name and email for payment
    but for Merchendiser I need those additional fields like: name of company, address of store etc.

  4. Melker Walter on June 28, 2017 at 7:31 am

    Great post, I always prefer coding than using a plugin for customizing woocommerce checkout page. I did also customize my checkout by changing the texts where I made a post here: http://www.22bulbjungle.com/woocommerce-change-text-on-checkout-page-quick-tutorial/

    Great write-up by the way!

  5. miguras on September 4, 2016 at 9:29 pm

    Hello. Great article. I made a plugin that do the same. You can disable/rearrange content inside the single product page and shop page. Also, you can remove checkout fields. I uploaded it to wordpress, so here you have the link WooEnhacer – WooCommerce Customizer if someone is interested.

Leave a Comment