Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide the Entire Section of WooCommerce Shipping fields?

WooCommerce provides a set of default shipping fields during checkout, but these fields may not always be necessary. For example, some stores may only need to collect a company name for shipping B2B orders, or they may only sell digital products that do not require shipping. In these cases, the store owner may want to hide the entire shipping section to streamline the checkout process and improve the user experience.

This post will help you to hide the entire section of Shipping fields in WooCommerce.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Solution: Hide the WooCommerce Shipping Field Section

Let’s say you sell eBooks on your WooCommerce website. When a customer adds an eBook to their cart and proceeds to checkout, WooCommerce will automatically display the shipping address field. This is because WooCommerce assumes that all products require a shipping address, even digital products.

However, since eBooks are digital products, there is no need to collect a shipping address from the customer. You can deliver the eBook to their email address.

To hide the shipping address field for customers who are purchasing digital products, you can use the following code snippet:

add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');

Output

When the customer visits the checkout page, the entire section of the shipping fields is hidden from the shipping forms.

How to Hide the Entire Section of WooCommerce Shipping fields?

Code Explanation

This code snippet adds a filter to the woocommerce_cart_needs_shipping_address function. This function returns a boolean value indicating whether or not the customer needs to enter a shipping address. By returning false from this function, we force WooCommerce to hide the shipping field section.

When a customer adds items to their cart and proceeds to checkout, WooCommerce checks to see if the customer needs to enter a shipping address. WooCommerce does this by calling the woocommerce_cart_needs_shipping_address function. If the function returns true, then the shipping field section is displayed. Otherwise, the shipping field section is hidden.

Conclusion

By adding the code snippet above, you can hide the entire shipping field section. In some cases, instead of hiding the entire section of shipping fields, you may need to display specific shipping fields based on the products you sell. For example, you can customize the checkout page by removing first name and last name from the WooCommerce shipping section.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x