Remove Checkout Fields For Downloadable Products In Woocommerce


The World's No.1 WooCommerce Plugin

Optimise Your Checkout Process By Removing Unnecessary Billing & Shipping Fields In WooCommerce Checkout

Statistically, the easier your checkout is to use the higher your chances are of converting traffic into paying customers.

One simple way to do this is to do away with unnecessary fields.

For example, if you are selling software or downloadable products then you don’t really need their billing or shipping address (unless you are using it for marketing purposes).

We can easily tell WordPress to remove these fields under the conditions that every single product in the cart is a virtual / downloadable product.

Below is an example of our super clean, super simple checkout

This is an example of our checkout – you could try buying something from us to see it in action!

This checkout is also powered by one of our plugins Alpha Checkout which works it’s magic to keep your checkout super clean and simple increasing your conversion rate without any extra settings. 

Alpha Checkout already has this virtual product feature already baked into it – no programming needed.

Enough of the shameless plug.

Copy and Paste This Snippet To Enable This Feature

You will need to copy paste the following snippet into your functions.php file.

If you’re not sure where functions.php is you can read our article about how to open functions.php here.

[php] /** * * @author Christopher Davies, WP Davies * @link * @link * @snippet Remove checkout fields for virtual/downloadable products * */ add_filter( ‘woocommerce_checkout_fields’ , ‘wpd_virtual_checkout_fields’, 100 ); function wpd_virtual_checkout_fields( $fields ) { $only_virtual = true; // Check if there are non-virtual products foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { if ( ! $cart_item[‘data’]->is_virtual() ) $only_virtual = false; } // If there are only virtual products in the cart if ( $only_virtual ) { unset($fields[‘billing’][‘billing_company’]); unset($fields[‘billing’][‘billing_address_1’]); unset($fields[‘billing’][‘billing_address_2’]); unset($fields[‘billing’][‘billing_city’]); unset($fields[‘billing’][‘billing_postcode’]); // unset($fields[‘billing’][‘billing_country’]); unset($fields[‘billing’][‘billing_state’]); unset($fields[‘billing’][‘billing_phone’]); add_filter( ‘woocommerce_enable_order_notes_field’, ‘__return_false’ ); add_filter( ‘woocommerce_cart_needs_shipping’, ‘__return_false’ ); // Set email as first field to help capture cart abandonment $fields[‘billing’][‘billing_email’][‘priority’] = -100; // must be first } return $fields; } [/php]

How To Remove Certain WooCommerce Checkout Fields

Every store is different, you will probably want to handle things a little differently to me.

Below is a list of all of the fields that you can remove.

To utilise this, simply add or remove fields in the body of the snippet where I have unset the fields.

[php] // Billing fields unset( $fields[‘billing’][‘billing_company’] ); unset( $fields[‘billing’][‘billing_email’] ); unset( $fields[‘billing’][‘billing_phone’] ); unset( $fields[‘billing’][‘billing_state’] ); unset( $fields[‘billing’][‘billing_first_name’] ); unset( $fields[‘billing’][‘billing_last_name’] ); unset( $fields[‘billing’][‘billing_address_1’] ); unset( $fields[‘billing’][‘billing_address_2’] ); unset( $fields[‘billing’][‘billing_city’] ); unset( $fields[‘billing’][‘billing_postcode’] ); // Shipping fields unset( $fields[‘shipping’][‘shipping_company’] ); unset( $fields[‘shipping’][‘shipping_phone’] ); unset( $fields[‘shipping’][‘shipping_state’] ); unset( $fields[‘shipping’][‘shipping_first_name’] ); unset( $fields[‘shipping’][‘shipping_last_name’] ); unset( $fields[‘shipping’][‘shipping_address_1’] ); unset( $fields[‘shipping’][‘shipping_address_2’] ); unset( $fields[‘shipping’][‘shipping_city’] ); unset( $fields[‘shipping’][‘shipping_postcode’] ); // Order fields unset( $fields[‘order’][‘order_comments’] ); [/php]

How To Disable Shipping When There Is Only Virtual Or Downloadable Products In The WooCommerce Cart

You will notice in my first snippet, on line 33 I have the following statement: add_filter( ‘woocommerce_cart_needs_shipping’, ‘__return_false’ );

This simply tells WooCommerce that if I only have virtual / downloadable products in my cart then we don’t need to do any shipping functions.

This will remove all of your shipping fields and do away with shipping calculations if relevant.

It’s a much more effective way of removing shipping functions then trying to unset all the fields.

That's How We Remove WooCommerce Checkout Fields For Virtual and Downloadable Products

Thanks for sticking it out to the end.

If you need any customisations or have any questions don’t hesitate to let me know – happy to write it up for you.

Just pop any questions in the comments below.

Thanks! Chris

Notify of
Inline Feedbacks
View all comments