Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide Unnecessary Billing and Shipping Fields in WooCommerce Checkout Blocks?

In WooCommerce checkout, the default checkout flow is to collect billing, shipping, and payment details for every order. But for free products like digital downloads or promotional giveaways, most of that information is unnecessary.

For zero-priced items, we can simplify checkout by hiding billing and shipping fields and only collecting the customer’s email. Paid products continue to follow the default woocommerce checkout flow.

In this post, we’ll focus on WooCommerce Blocks checkout and see how to streamline the process for free orders, hiding unnecessary fields while keeping paid orders unaffected.

Solution: Hide Unnecessary billing and Shipping fields in WooCommerce Checkout Blocks

With the code snippet below, we are customizing the WooCommerce Blocks checkout page to hide all billing and shipping fields for free products, except the country field. The country field remains visible to prevent any validation errors during checkout.

// Hide billing and shipping fields in WooCommerce Blocks checkout for free orders
add_filter('woocommerce_get_country_locale', function($locale) {

    // Only proceed if cart exists
    if ( ! WC()->cart ) {
        return $locale;
    }

    // Only proceed if total is zero
    if ( WC()->cart->get_total('edit') > 0 ) {
        return $locale;
    }

    foreach ( $locale as $country_code => $fields ) {
        // BILLING and Shipping FIELDS
        $locale[$country_code]['first_name']['hidden'] = true;
        $locale[$country_code]['last_name']['hidden'] = true;
        $locale[$country_code]['company']['hidden'] = true;
        $locale[$country_code]['address_1']['hidden'] = true;
        $locale[$country_code]['address_2']['hidden'] = true;
        $locale[$country_code]['city']['hidden'] = true;
        $locale[$country_code]['state']['hidden'] = true;
        $locale[$country_code]['postcode']['hidden'] = true;
        $locale[$country_code]['phone']['hidden'] = true;
    }

    return $locale;
});

Output

When the cart total is zero, all billing and shipping fields are hidden, and the customer only needs to enter their email to complete the order. 

If the cart total is greater than zero, the standard checkout flow applies, showing all billing, shipping, and payment fields as usual.

Simplifying the checkout process for free products can significantly enhance the user experience by eliminating unnecessary steps. However, if you ever need to collect additional information from customers, such as their GSTIN, delivery notes, or preferences, you can easily do so too. By extending your checkout form using WooCommerce’s new Checkout Fields API, you can now easily add custom checkout fields to WooCommerce Checkout Blocks.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.