I am trying to change the tax for the user who will fill in the "tax" field. But for some reason the tax does not change. Although when using such a condition with the default city field WC()->customer->get_billing_city() == 'xxx'), everything will change.
add_action( 'woocommerce_before_calculate_totals', 'custom_cart_items_tax_prices', 10, 1 );
function custom_cart_items_tax_prices( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
if ( WC()->customer->get_billing_city() == 'xxx') {
foreach ( $cart->get_cart() as $cart_item ) {
$product_id = $cart_item['data']->get_id();
if ($product_id==11) {
$cart_item['data']->set_tax_class( 'Test' );
}
}
}
}
What kind of mistake could there be?