Remove Billing Address for Free Virtual Orders in WooCommerce

writing
  1. Blogging for Benjamin Competition
  2. Why I'm Grateful to Work on the Web
  3. 24 Pull Requests
  4. Update Downloadable Product's Expiration Date in WooCommere
  5. Get Lost in the Flow and Work for More Than a Salary
  6. Why A Plugin's Popularity Matters
  7. Why You Should (Or Shouldn't) Use Premium Plugins
  8. WooCommerce Terms & Conditions
  9. Only Ship to Continental United States with WooCommerce
  10. Just Talk
  11. Why I Love Jetpack
  12. Making Jetpack Better
  13. Remove Billing Address for Free Virtual Orders in WooCommerce
  14. Notify Admin of Customer Address Change in WooCommerce
  15. Open Your Self Up To New Possibilities
  16. 2013 Resolutions Review
  17. Create a Community
  18. Tips for Starting a Community
  19. The Intent of Goals
  20. Create The Ultimate Invoicing System Using WooCommerce
  21. Change From Address in Ninja Forms
  22. Work With People Who Inspire You
  23. Contact Form 7 & MailPoet Integration
  24. Monotasking
  25. Giving Back to The Community
  26. Adding Fuctionality to Lean Plugins
  27. Choose Stripe For a Payment Gateway
  28. A Dip Into Entrepreneurship
  29. Reward Yourself
  30. Blogging for Benjamin Plugin
  31. Blogging for Benjamin Wrap Up

One of the best things about WooCommerce is the slick one page checkout. It's really fast since you don't need to reload any pages and it's smart enough to know when you don't need shipping information when you're only purchasing virtual/downloadable products. We like to make sure the site manager has all of the data available to them so if you have a free download available on your site WooCommerce still asks the user for all of their billing address fields which works great for most users.

Remove Billing Address Fields

WooCommerce Minimal Checkout

The WooCommerce checkout page with the billing section removed.

If you don't need that extra data and would prefer fewer steps in the checkout process you can of course dig right into our awesome hooks system and remove those fields manually.

I wanted to look into this so I created a mini plugin which removes the billing fields if the order doesn't require shipping and if the order total is exactly zero. I’m including the plugin here for you to look at the code but you can also go the plugins home page and download it, extract the zip file, and upload the folder to your /wp-content/plugins/ directory of your site.

<?php
/**
* Plugin Name: WooCommerce Remove Billing Fields for Free Virtual Products
* Plugin URI: https://gist.github.com/BFTrick/7873168
* Description: Remove the billing address fields for free virtual orders
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Patrick Rauland
* @since 1.0
*/
function patricks_billing_fields( $fields ) {
global $woocommerce;
// if the total is more than 0 then we still need the fields
if ( 0 != $woocommerce->cart->total ) {
return $fields;
}
// return the regular billing fields if we need shipping fields
if ( $woocommerce->cart->needs_shipping() ) {
return $fields;
}
// we don't need the billing fields so empty all of them except the email
unset( $fields['billing_country'] );
unset( $fields['billing_first_name'] );
unset( $fields['billing_last_name'] );
unset( $fields['billing_company'] );
unset( $fields['billing_address_1'] );
unset( $fields['billing_address_2'] );
unset( $fields['billing_city'] );
unset( $fields['billing_state'] );
unset( $fields['billing_postcode'] );
unset( $fields['billing_phone'] );
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'patricks_billing_fields', 20 );
// That's all folks!

Modifying the Checkout Form Labels

Since this plugin removes all of the billing fields we should also probably remove the “Billing Address” header on the checkout page. I've gone ahead and removed it by using my favorite gettext filter and replacing the string with an empty string.

If you're using a different language you'll have to change my gettext filter or go into the woocommerce/templates/checkout/form-billing.php template and modify it. Here's a handy guide to modifying WooCommerce templates.

I hope this helps make your checkout page a little more slick! 🙂

Update 2014-04-25

Due to many of the comments I decided to update this script so that it removes all of the billing fields except the email field. This way you capture their email address and downloadable files can be emailed to them. If you want the older version which removes all of the fields go to the plugin homepage and click on Revisions to access the earlier versions.

Photo Credit: Abdulghani Alsooqi via Compfight cc

30 thoughts on “Remove Billing Address for Free Virtual Orders in WooCommerce

  1. I tested out your plugin and am writing to provide some friendly feedback. For the free virtual product checkout page, the major issue is with a new user (i.e. no existing account) use case. As you can see, I’m prompted to create a password without having to enter any other customer information – not even an email address.

    The other thing I noticed is that the “Billing Address” label is removed when you’re checking out any kind of product(s); the hidden field label is not limited to the free virtual product use case. Is this expected functionality?

    • Hey Ian,

      Thanks for your feedback! You’re totally right it would be nice if you wanted to create an account to be able to do so. I didn’t think about that when writing the plugin.

      The billing address should only be removed if the product is both virtual and free. There must be some use case that I didn’t account for. I’m pretty busy with the blogging for benjamin competition but hopefully I (or someone else) can look into these issues. 🙂

  2. Hey! Thanks for providing this workaround! I tried it out on my site, but for some reason, when I click the download link, I get an error saying “invalid email.” Someone in a forum mentioned that in order for the download to go through the customer must provide their email and country of residence. Any insight into this?

  3. This plugin ddin’t remove my billing address for Woo Commerce Version 2.1.3. I made my product free and removed shipping.

  4. this plugin has broken my checkout sadly http://footballpredictor.net/checkout the links in the checkout no longer work ie continue, Shipping Address & Review & Payment and the default page is billing address that’s meant to be disabled but all it has done is hidden the link on the left could you help me out please

    • Hey Michael, sorry I can’t help you out – but I did check this a week or so ago and it was working. There’s most likely some sort of conflict with your theme or some of your plugins. I would suggest disabling all of those to find the root of the issue.

  5. is there a way to remove the “shipping address” field if a user chooses pickup as its delivery method? Currently my site has “flat rate shipping” and “local delivery” as its options for delivery methods. But “local delivery” is actually “pickup at the office” for users using the site. Therefore, it wouldnt make sense if a user needs to input shipping address. But currently, shipping address is displaying on my checkout page. So i would like to know whether its possible to remove it depending on the user’s selection for delivery method.

    • Unfortunately neither Local Pickup nor Local Delivery hide the shipping fields. Although this shouldn’t be a big deal since by default the customer only has to enter the billing information unless they check the Ship to a different address? checkbox. There are several themes to modify the checkout process if you have to enter a shipping address it’s probably because of your theme.

  6. Excellent little plugin! 🙂
    One question:

    Is there a way to still require the user to enter an email address?

    Thanks!

    • I originally typed “no” but I had some free time this morning and it seems like a lot of users still need the email field. I’ve now updated this snippet to 2.0 and now it omits all of the fields except the email field. Now you capture their email address and downloadable files can be emailed to them. I hope that helps! 🙂

  7. Doesn’t work for me. The fields are hidden but when I try to checkout with my $0 order I get error messages telling me the phone, address, city, etc. are required.

  8. Please ignore my last comment… seems a small customization I had done broke the code.

  9. Very promising – thank you Patrick. I am trying to use your plugin along with “Checkout Field Editor” so that virtual free orders collect first/last name, email and the option to create an account, but virtual and downloadable orders that cost money collect the above plus address info including country (so my payment processor will accept the order). It seems that I can use one or the other plugins but not both, based on my limited coding knowledge. Is there a tweak to make that happen? Thanks in advance.

  10. Hi this is really a good plugin indeed!
    I have a question tho… I noticed that when I installed it even the Billing field at the “My Account” disappeared too! This is when you go to My Account page and then under “Billing Address” you click on Edit.
    Even if a customer has previously added this information, the plugin wont allow the user to edit it or even see it.

    Any ideas how to solve this issue?
    Thank you!

  11. You are D MAN! Thank you soooooooooooooooooooooooooooooooooooooooooooooooooooooo much!!!!

    P.S. Add donation option / buy me a coffee option somewhere! I really wanted to buy you a cup of coffee or a beer for this!

  12. Sir.. you are a wizard. If been looking several hours to find this. And now my site just does what it needs to do. Credits for you, thank you so much!

  13. Great help! Thank you very much!

  14. Hi, it seem to not work anymore with new Woocommerce version or maybe with new WordPress version 4.4

  15. I ended up breaking my site the first time but manage to get it the second time.
    I discovered a safe way to do this in the process 🙂

  16. 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.

  17. This is exactly what I was looking for; thanks! It’s especially useful to be able to still capture the email address.

    I have a related question: is it possible to remove the text at the bottom of the checkout page that reads “Clicking the order button will charge your credit card – or redirect to PayPal….”, since their credit card/Paypal will not be charged?

    Keeping in mind that I know absolutely no code and do most everything via plugins. One day I’ll learn code…

    Thank you so much!

    Mariana

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.