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 topUse 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 topThis 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 topThis 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 );
}
Related customization
↑ Back to topVAT 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.