在 woocommerce 中获取税率名称的麻烦

trouble with getting tax rate name in woocommerce

您好,我现在想获取 woocommerce 中的税率名称。我有什么办法可以得到图中圈出的值:http://i.imgur.com/niSraFa.png

我当前的代码:

$items = $order->get_items();
        $lineItem = array();
        $productInfo = $orderInfo = array();
        $order_items = array();
        if ($items) foreach ($items as $item_key => $item_value) {
            $_tax = new WC_Tax();
            $_product = $order->get_product_from_item( $item_value );
            $product_tax_class = $_product->get_tax_class();
            $tax_class = $item_value['tax_class'];

您将使用 WC_Tax()->find_rates() 方法。它需要一个数组作为参数,在您的情况下,它是 array( 'country' => 'NO' ) 和 returns 匹配税率的数组。该数组的键之一是 label,其中包含税率的名称。

$tax = new WC_Tax();
$country_code = 'NO'; // or populate from order to get applicable rates
$rates = $tax->find_rates( array( 'country' => $country_code ) );
foreach( $rates as $rate ){
    $tax_rate_name = $rate['label'];
}

要查找特定订单的适用税率,请使用订单上 shipping/billing 地址的值填充 find_rates() 的数组。