Last active
February 15, 2021 14:08
-
-
Save rynaldos-zz/edeb6c82904267d19538f1e49ce26894 to your computer and use it in GitHub Desktop.
filter the countries where the VAT number field will show up for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_eu_vat_number_country_codes', 'woo_custom_eu_vat_number_country_codes' ); | |
function woo_custom_eu_vat_number_country_codes( $vat_countries ) { | |
// only show field for users in BE | |
return array( 'BE' ); | |
} |
@rynaldos can you update the script?
If you need to remove a couple of countries use array_diff passing an array of the country codes you wish to remove as the second param, no need to loop and unset values.
As @jakecausier mentioned pass the modified array through array_values to reindex the values.
add_filter( 'woocommerce_eu_vat_number_country_codes', 'woo_custom_eu_vat_number_country_codes' );
function woo_custom_eu_vat_number_country_codes( $vat_countries ) {
$display_vat = array_diff($vat_countries, ['SE', 'GB']); // remove countries in second array
return array_values($display_vat); // reindex array
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone that is manipulating/removing the countries through an unset or such, pass the returning array through array_values first. I discovered that the values embedded on the page also picked up the array keys which was causing my VAT field from stop appearing completely.