WPSlash

Set Default Values to WooCommerce Checkout Fields and Hide Them

Saturday November 2, 2019

All of our customers asking us how to remove some fields from WooCommerce checkout form when using WooFood or even if you are not using it.

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

Leave a Comment

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

Related Articles

WooFood

How to Disable Coupons for Delivery Orders in WooCommerce

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy. Why Restrict Coupons for Delivery Orders? Offering coupons is a great way to attract customers, but in food […]
June 20, 2023
WooFood

How to Automatically Re-Enable Disabled Products in WooFood Once a Day

If you’re running a WooCommerce-powered restaurant ordering system using WooFood, you might have products that automatically get disabled due to stock limits or availability settings. To ensure a smooth customer experience, you can automate the re-enabling process using a scheduled WordPress cron job. This method allows you to reset all product availability once a day, ensuring your menu stays active without manual intervention. Why […]
March 8, 2023
WooFood

How to Add Live Product Search to WooFood in WooCommerce

Enhancing the user experience of your WooCommerce-powered restaurant ordering system is crucial, and adding a live product search feature can significantly improve navigation. This feature allows customers to quickly find food items in your WooFood-powered menu without manually browsing through categories. In this article, we’ll show you how to integrate a live product search above the accordion menu in WooFood using a simple jQuery script and PHP snippet. […]
December 29, 2022