Virtual product checkout billing address issue

This topic has 2 replies, 2 voices, and was last updated 1 months, 1 weeks ago ago by Luca Rossi

  • Avatar: Wanan
    Wanan
    Participant
    October 26, 2025 at 04:06

    When a product is set as a virtual product, how can I hide the detailed billing address fields? I used a plugin, but it doesn’t work.

    1 Answer
    Avatar: Justin
    Luca Rossi
    Support staff
    October 26, 2025 at 08:43

    Hello @Wanan,

    Do you mean that when checking out with a cart containing only virtual products, the billing address fields should be hidden?

    Please try adding the following custom code to the functions.php file located in your child theme:

    
    add_filter( 'woocommerce_checkout_fields', 'hide_billing_address_if_virtual_products' );
    
    function hide_billing_address_if_virtual_products( $fields ) {
        // Check if all products in the cart are virtual
        $only_virtual = true;
    
        foreach ( WC()->cart->get_cart() as $cart_item ) {
            if ( ! $cart_item['data']->is_virtual() ) {
                $only_virtual = false;
                break;
            }
        }
    
        // If all products are virtual, remove billing address fields
        if ( $only_virtual ) {
            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'] );
        }
    
        return $fields;
    }
    

    I hope this helps.

    Best regards,
    8Theme Team

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.