Make VAT number optional for B2C customers
Friday, 04 November 2022
WooCommerce B2B has the option “Make VAT number field required” which allows you to make the VAT number field mandatory or optional.
In some particular scenarios (especially in hybrid B2C / B2B shops), based on your specific needs, you may need to differentiate the behavior (optional / mandatory) based on the customer.
For example, if you want to make VAT number field optional for presumed B2C customers, edit functions.php file that you find in your site’s FTP space in:
and insert this code:
With this snippet, if the customer is not logged in, or belongs to special GUEST group, or does not belong to any group, it will be considered B2C and the VAT number field will be forced as optional, regardless of WooCommerce B2B “Make VAT number field required” option.
It is advisable not to edit the theme files directly, but to use a child theme.
For more information on child themes, please read: WordPress Official guide on Child Themes