# Skip Address Fields for Virtual-Only Orders

> Removes the billing address fields from the classic checkout when everything in the cart is virtual or downloadable, keeping only name and email.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, virtual, digital
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-hide-address-for-virtual/

## Code

```php
add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
    if ( ! WC()->cart || WC()->cart->needs_shipping() ) {
        return $fields;
    }

    foreach ( WC()->cart->get_cart() as $item ) {
        if ( ! $item['data']->is_virtual() ) {
            return $fields;
        }
    }

    // Billing fields to keep for virtual orders.
    $keep = array( 'billing_first_name', 'billing_last_name', 'billing_email' );

    foreach ( array_keys( $fields['billing'] ) as $key ) {
        if ( ! in_array( $key, $keep, true ) ) {
            unset( $fields['billing'][ $key ] );
        }
    }

    return $fields;
}, 20 );
```

## Notes

Some payment gateways need the billing address for fraud checks; test a payment before going live.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Skip Address Fields for Virtual-Only Orders" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
