How to add a GST number field to WooCommerce checkout and order emails

If you’re running a WooCommerce store in India or working with B2B clients, you may need to collect GST numbers during checkout. In this tutorial, you’ll learn how to add an optional GST number field on the WooCommerce checkout page, save it with the order, and display it in the admin panel as well as in the order confirmation emails.

Step 1: Add GST Number Field to Checkout Page

Use the following code in your theme functions.php file to add a new optional field for the GST number just below the billing fields.

// Add GST Number field to checkout
add_action('woocommerce_after_checkout_billing_form', 'add_gst_field_to_checkout');
function add_gst_field_to_checkout($checkout) {
    echo '<div id="gst_number_field"><h3>' . __('GST Number (Optional)') . '</h3>';

    woocommerce_form_field('gst_number', array(
        'type'        => 'text',
        'class'       => array('form-row-wide'),
        'label'       => __('GST Number'),
        'placeholder' => __('Enter your GST number if applicable'),
        'required'    => false,
    ), $checkout->get_value('gst_number'));

    echo '</div>';
}

Step 2: Save the GST Number to Order Meta

Use the following code in your theme functions.php file to to save the entered GST number into the order’s metadata.

// Save GST number in order meta
add_action('woocommerce_checkout_update_order_meta', 'save_gst_number_order_meta');
function save_gst_number_order_meta($order_id) {
    if (!empty($_POST['gst_number'])) {
        update_post_meta($order_id, '_gst_number', sanitize_text_field($_POST['gst_number']));
    }
}

Step 3: Show GST Number on Admin Order Page

Admins should be able to view the GST number from the WooCommerce dashboard under the order details. Use the following code in your theme functions.php file.

// Show GST number in admin order page
add_action('woocommerce_admin_order_data_after_billing_address', 'display_gst_in_admin_order', 10, 1);
function display_gst_in_admin_order($order) {
    $gst_number = get_post_meta($order->get_id(), '_gst_number', true);
    if (!empty($gst_number)) {
        echo '<p><strong>' . __('GST Number') . ':</strong> ' . esc_html($gst_number) . '</p>';
    }
}

Step 4: Show GST Number in Order Emails

To include the GST number in the order emails (for both admin and customer), below the billing address section, add the following code in your theme functions.php file.

// Add GST number to emails below billing address
add_filter('woocommerce_email_customer_details_fields', 'add_gst_to_order_email', 10, 3);
function add_gst_to_order_email($fields, $sent_to_admin, $order) {
    $gst_number = get_post_meta($order->get_id(), '_gst_number', true);
    if (!empty($gst_number)) {
        $fields['gst_number'] = array(
            'label' => __('GST Number'),
            'value' => $gst_number,
        );
    }
    return $fields;
}

Note: Always test this on a staging site before applying to a live WooCommerce store. If you use custom themes or plugins that modify the checkout or email templates, adjust the code accordingly.

Plugin version of the same codes is also available on Github.