EU VAT Number developer snippets

This developer reference shows how to control which countries display the EU VAT Number field at checkout.

Add one of these examples to a custom plugin or another site-specific customization layer. Test the change on a staging site before using it on a production store.

Note:

This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.

Before you begin

↑ Back to top
  • Make sure the EU VAT Number extension is installed and active.
  • Add the code with a custom plugin, a child theme, or a code-snippet manager.
  • Use only one of the examples below. Each example replaces the extension’s default list of countries.
  • Test the resulting checkout behavior on a staging site before using it in production.

Choose which countries display the VAT field

↑ Back to top

Use the woocommerce_eu_vat_number_country_codes filter to change the countries where the VAT number field is available.

Show the field only for Belgium

↑ Back to top

This example replaces the default list with Belgium (BE).

add_filter( 'woocommerce_eu_vat_number_country_codes', 'wccom_show_vat_number_for_belgium' );

function wccom_show_vat_number_for_belgium( $vat_countries ) {
    // Show the VAT number field only for customers in Belgium.
    return array( 'BE' );
}

Hide the field for selected countries

↑ Back to top

This example removes Sweden (SE) and the United Kingdom (GB) from the default list while keeping the remaining countries.

add_filter( 'woocommerce_eu_vat_number_country_codes', 'wccom_hide_vat_number_for_selected_countries' );

function wccom_hide_vat_number_for_selected_countries( $vat_countries ) {
    // Remove Sweden and the United Kingdom from the VAT field countries.
    $vat_countries = array_diff( $vat_countries, array( 'SE', 'GB' ) );

    return array_values( $vat_countries );
}
↑ Back to top

VAT numbers are stored in the _billing_vat_number order meta field. The wc_eu_vat_get_vat_from_order( $order ) function retrieves the value, including the legacy _vat_number field.

To move the VAT field to another checkout location, see this tutorial for reordering the EU VAT field.

Related Products

Offer Royal Mail shipping rates to your customers.

Get shipping rates for your WooCommerce store from the Australia Post API, which handles both domestic and international parcels.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.