Checkout

WooCommere Remove Checkout Billing Fields For Virtual Product Orders

WooCommerce checkout with reduced fields due to virtual product being the only product in the order

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This snippet checks the cart contents and will remove the billing fields if there are only virtual products in the order.

This means your customers will only need to enter their first name, last name, email address, and optionally any order notes.

If you wish to remove Order notes you can view the guide here: How to remove the Order Notes section from the WooCommerce checkout.

Keep in mind, some payment gateways require billing fields, particularly the postcode, to process orders.

/**
 * Snippet Name:	WooCommere Remove Checkout Billing Fields For Virtual Products
 * Snippet Author:	ecommercehints.com
 */

add_filter( 'woocommerce_checkout_fields' , 'ecommercehints_remove_checkout_billing_fields_if_virtual_product' );
function ecommercehints_remove_checkout_billing_fields_if_virtual_product( $fields ) {

   $only_virtual_in_cart = true; // If there is a physical product too, don't remove the fields

   foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

      if ( ! $cart_item['data']->is_virtual() ) {
		  $only_virtual_in_cart = false;
	  }
   }
	if ($only_virtual_in_cart) {
		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']);
	}
     return $fields;
}

Snippet Benefits

  • Reduce friction at the checkout by removing unnecessary fields.
  • By reducing the number of steps you are more likely to increase the conversion rate and reduce the checkout abandonment rate.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 10% off on your first month with us.

26027
WELCOME OFFER