AI Verified

Name

WooCommere Remove Checkout Billing Fields For Virtual Product Orders

About

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.

Language

PHP

Rating

Voted: 2 by 2 user(s)

How to Setup Snippet

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

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://www.ecommercehints.com/woocommere-remove-checkout-billing-fields-for-virtual-products

Codevault

ecommercehints

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.ecommercehints.com/

History

Last modified:

02/02/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommere Remove Checkout Billing Fields For Virtual Product Orders

 
                    
1/**
2 * Snippet Name: WooCommere Remove Checkout Billing Fields For Virtual Products
3 * Snippet Author: ecommercehints.com
4 */
5 
6add_filter( 'woocommerce_checkout_fields' , 'ecommercehints_remove_checkout_billing_fields_if_virtual_product' );
7function ecommercehints_remove_checkout_billing_fields_if_virtual_product( $fields ) {
8 
9 $only_virtual_in_cart = true; // If there is a physical product too, don't remove the fields
10 
11 foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
12 
13 if ( ! $cart_item['data']->is_virtual() ) {
14 $only_virtual_in_cart = false;
15 }
16 }
17 if ($only_virtual_in_cart) {
18 unset($fields['billing']['billing_company']);
19 unset($fields['billing']['billing_address_1']);
20 unset($fields['billing']['billing_address_2']);
21 unset($fields['billing']['billing_city']);
22 unset($fields['billing']['billing_postcode']);
23 unset($fields['billing']['billing_country']);
24 unset($fields['billing']['billing_state']);
25 unset($fields['billing']['billing_phone']);
26 }
27 return $fields;
28}

2

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Buy Now Button

Added: 1 year ago

Last Updated: 1 year ago

This snippet generates a secondary button “Buy Now’.Introducing this button allows users to checkout more quickly as they skip the entire cart journey of the buying journey.This is particularly useful...

WooCommerce

AI Verified

0

WooCommerce Stock Status Progress Bar for Variations

Added: 1 year ago

Last Updated: 1 year ago

An expanded on version of ecommercehints.com's WooCommerce Stock Status Progress Bar This snippet inserts a progress bar on both single products and variable products' pages, allowing customers t...

WooCommerce

AI Verified

1

Restrict Accessing Pages until Product Purhased

Added: 1 year ago

Last Updated: 8 months ago

Lock away access to Pages until certain WooCommerce Products are purchased,

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

5

WooCommerce Show Number Of People Viewing Product

Added: 1 year ago

Last Updated: 1 year ago

We want to make this solution absolutely clear from the outset. This snippet does NOT generate the actual number of people viewing the product. It shows a randomly generated number in the range of two...

WooCommerce

AI Verified

4

WooCommerce Show Number Of Units Sold On Product Page

Added: 1 year ago

Last Updated: 8 months ago

Showing the number of product units sold on the single product page is a great way to introduce Fear Of Missing Out (FOMO). You can highlight how many products are sold to let customers know a product...

WooCommerce

AI Verified

2

WooCommerce Add Content Under The Proceed To Checkout Button On The Cart Page

Added: 1 year ago

Last Updated: 1 year ago

How many times have you bought something online and seen trust symbols near the proceed to checkout button on the cart page? “30 Day Money Back Guarantee” or “Secure Checkout” are popular examples. By...