Below you will find another handy snippet related to B2B Market. If you use the WooCommerce plugin B2B Market without German Market, it is not possible to validate the VAT ID automatically and then disable tax calculation during checkout. On request, the prices in the shop itself are displayed as net prices using B2B Market’s built-in features, but as soon as the checkout starts, taxes are calculated as usual. If you do not mind validating VAT ID numbers manually, you can use the following function to exempt selected customer groups from tax calculation.
As usual, you can add the code to your functions.php or activate it via a plugin such as “Snippets”. Simply fill the array $b2bRoles with the slugs of your B2B Market groups, nothing more is needed.
function osulzer_excempt_group_from_vat($post_data) {
# enter the slugs of the b2b groups whose customers pay no taxes
$b2bRoles = [
'role_1',
'role_2',
];
$userdata = is_user_logged_in() ? get_userdata(get_current_user_id()) : false;
if($userdata) {
$isB2B = count(array_intersect($userdata->roles, $b2bRoles)) != 0;
if($isB2B) {
# set the user to tax exempt
WC()->customer->set_is_vat_exempt( true );
}
}
}
add_action( 'woocommerce_checkout_update_order_review', 'osulzer_excempt_group_from_vat' );
I am happy to support you with building your B2B shop. Get in touch with your project in a non-binding initial consultation.




