woocommerce 订单仪表板上没有运费税

There's no shipping tax on woocommerce order dashboard

运费税费显示在除订单仪表板之外的所有地方。 我以编程方式添加运费,所以我认为可能存在错误?但同时没有任何意义,因为在结账时已收取运费,没有任何问题。 我应该查看哪些提示?

当然是代码.. 我正在尝试在过滤器 woocommerce_package_rates:

中应用税收的流行代码
$taxes = array();
// Taxes: Loop through the shipping taxes array (as they can be many)
foreach ($rate->taxes as $key => $tax){
    if( $tax > 0 ){
        $initial_tax_cost = $tax; // Get the initial tax cost

        $tax_rate    = $initial_tax_cost / $initial_cost; // Get the tax rate conversion

        $taxes[$key] = $new_cost * $tax_rate; // Set the new tax cost in taxes costs array

    }
}
$rates[$rate_key]->taxes = $taxes;

嗯,在我的例子中,$tax 是 alywas 0。所以我放弃了整个东西,并像这样应用它:

 $rates[$rate_key]->taxes = [$new_cost * $tax_rate];

它在结帐时有效,但在订单仪表板上无效,因此我问了这个问题。

改为:

$taxes = WC_Tax::calc_shipping_tax( $rate->cost, WC_Tax::get_shipping_tax_rates() );
$rate->set_taxes($taxes); 

我不知道为什么索引必须大于 0..但是好吧..现在一切正常。