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
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
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. 🙂
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?
Hi Davina,
You will need the email address so if you’re hiding the email address with other code that could break things. It could also be an invalid download path. Did you make sure that the Grant access to downloadable products after payment setting is checked?
Do you have guest checkout disabled?
Same problem here: “invalid email.”
My guest checkout is ON
Grant access to downloadable products after payment CHECKED
Hey Lucio, without looking into this further it looks like downloadable products do require an email address (or to be logged in). Try making the product
virtual
but notdownloadable
and then put the download link in thePurchase Note
field under theAdvanced Tab
on the edit product page. I hope that helps! 🙂This plugin ddin’t remove my billing address for Woo Commerce Version 2.1.3. I made my product free and removed shipping.
Hey Wendy, I tried this my self a week or two ago. It does work. There’s most likely a conflict with your theme or a plugin. I would disable those and try again.
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.
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.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! 🙂
Perfecto! You, sir, are AWESOME!!! 🙂
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.
Please ignore my last comment… seems a small customization I had done broke the code.
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.
Hey Mike,
Yeah this is possible but you’d have to add some code to my existing snippet. I’d recommend Codeable (aff) for this.
Many thanks for the advice, Patrick!
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!
Unfortunately I don’t have the time right now to test/fix this. I would wrap a conditional tag around the code so that it only works on the checkout screen. I believe the conditional we want is
is_checkout()
.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!
Thanks Nina! I really appreciate that! 🙂
If you want to help me out buy my WooCommerce book. I get a few bucks from that and you get a book with 90+ tutorials. 🙂
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!
Great help! Thank you very much!
Hi, it seem to not work anymore with new Woocommerce version or maybe with new WordPress version 4.4
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 🙂
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.
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