Hiding Specific Checkout
Fields in Woocommerce

You can get rid of specific checkout fields in more than one way. Beneath is a series of solutions to hide checkout fields by virtual, category, product ID, shipping or coupon name.

Along with some minor CSS tweaks, we can easily achieve a more user friendly experience for our Woocommerce customers.

Paste one of the codes underneath in your functions.php to activate it. Alternatively, there’s also a number of plugins to remove specific checkout fields in Woocommerce.

By Virtual

It’s always a huge hassle for customers to fill out details which isn’t needed to buy a product. To make their life easier, we’ll hide some of the checkout fields in Woocommerce.

This first code ensures the billing fields will be omitted from the checkout – once you check the product as being virtual. The code will loop through the cart to see if the product(s) are virtual or not.

If you have more than one product, where one is virtual and the other isn’t, all normal checkout fields will follow. As it is conditional, hiding the specific checkout fields will only occur when the product(s) in the cart are virtual.

By Shipping

We can achieve the same result by using the cart’s needs_shipping method as viewed below. Instead of making a query to see if the product is virtual or not, it checks to see if the products in the cart need shipping.

You can always change the if statement from false to true if you want to omit certain fields for products being shipped instead.

By Category, Product or Coupon

To go even further, we could also remove the checkout fields by specific product IDs, categories or even coupons being used.

Please keep in mind that you can’t copy paste the following code without small alterations to it. For instance, the arrays in $product_ids, $categories and $coupons needs to be modified to suit your product ids, category names and/or coupon names.

Plugins

If you’d rather just get a plugin to alter your custom checkout fields for all your products in Woocommerce, and you’re using WordPress, then another easy solution would be the following:

Paid plugins

3 Comments

  1. It really does suck to fill out so many fields for downloadable products in Woocommerce… I really wish their system had custom fields you could add or take away built into it from the start. Thanks for this…

  2. I’m struggling with this:
    – When a coupon is applied I need to show the order comments as a required field.
    – When no coupon is used I want to hide the order comments.

    I can hide it the comments with the snippet shown above, but it’s still a required field, so impossible to check out. I assumed hiding meant that the required setting became obsolete automatically.

    Any pointers for this scenarion?

Leave a Reply

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