You can make the billing company checkout field update checkout on change with the following (without using any additional javascript or jQuery code) and check for country "HR" (Croatia):
add_filter( 'woocommerce_checkout_fields' , 'billing_company_trigger_update_checkout_on_change', 10, 1 );
function billing_company_trigger_update_checkout_on_change( $fields ) {
$fields['billing']['billing_company']['class'][] = 'update_totals_on_change';
return $fields;
}
add_action( 'woocommerce_checkout_update_order_review', 'checkout_vat_exempt_based_on_billing_company', 10, 1 );
function checkout_vat_exempt_based_on_billing_company( $post_data ) {
parse_str($post_data, $results); // Since Php 7.2, the 2nd argument is recommended in parse_str() function
extract($results);
$customer = WC()->customer;
// When billing company is filled and country is Croatia: Exempt taxes
if ( ! empty($billing_company) && $billing_country === 'HR' && ! $customer->is_vat_exempt() ) {
$customer->set_is_vat_exempt( true );
}
elseif ( $customer->is_vat_exempt() ){
$customer->set_is_vat_exempt( false );
}
}
To handle shipping country instead of billing country just replace in the code the variable $billing_country
by $shipping_country
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Note: Since a while, global $woocommerce
and $woocommerce
are replaced simply by WC()