基于购物车小计的税收

Tax based on cart subtotal

当我向欧盟国家销售价值超过 150 欧元的订单时,我正在尝试使用下面的代码将税率设置为零,但我无法让它工作。知道我做错了什么吗?

add_filter( 'woocommerce_product_get_tax_class', 'eu_tax_rate_based_on_subtotal', 1, 2 );
function eu_tax_rate_based_on_subtotal( $tax_class, $product ) {
    $EU_countries = array('AT','BE','BG','CY','CZ','DE','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK');
        if ( in_array( WC()->customer->get_shipping_country(), $EU_countries ) ){
            if ( WC()->cart->subtotal >= 150 )
                $tax_class = 'zero';
        }
return $tax_class;
}

如果您想在没有动态要求的情况下删除税费,请使用此过滤器。

function sto_calc_tax($taxes, $price, $rates, $price_includes_tax, $deprecated){
    if (WC()->cart->subtotal >= 150 && in_array( WC()->customer->get_shipping_country(), array('AT','BE','BG','CY','CZ','DE','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK') ) ){
        foreach ($taxes as $index => $tax) {
            $taxes[$index] = 0;
        }
    }
    return $taxes;
}
add_filter('woocommerce_calc_tax', 'sto_calc_tax', 10, 5);