Set Default Values to WooCommerce Checkout Fields and Hide Them
the

All of our customers asking us how to remove some fields from WooCommerce checkout form when using WooFood.

Because WooFood need these fields (like City and Postal Code to be able to calculate the distance between the customer and the store) we decided to write this small tutorial .

Instead of using unset  to remove the fields we will set default values to the fields we want and we will hide them via CSS.

First Step is to Set the Default values we want to our checkout fields

Let’s say that we want to set a default city and a postal code. Here is a small snippet that will do the job easily.

Just copy and paste the following code into the functions.php file inside your child theme or your main theme and change the values to yours.

add_filter( 'woocommerce_checkout_fields', 'woofood_set_default_checkout_field_values' );

function woofood_set_default_checkout_field_values($fields) {
    $fields['billing']['billing_city']['default'] = 'New York';
    $fields['billing']['billing_postcode']['default'] = '10002';

    return $fields;
}

The first part is done as you have set the default values to Billing City and Billing Postal Code.

Second Step is to hide these fields from checkout page

Copy and paste the following code into style.css of your child theme or use the customiser (Appearance > Customize > Additional CSS(on the bottom)) .

#billing_city_field
{
	display:none!important;
}
#billing_postcode_field
{
	display:none!important;
}

*Note: Don’t forget to clear your browser cache and your site cache(if you are using any caching plugin)

You are ready! Now the fields will be hidden on checkout and will always have the default city and postal code you specified above