获取单独订单的含税总税额 class

Get separate Order's tax totals amounts with tax class

我正在为 woocommerce 制作个人 PDF 发票插件。

我们的一些产品以降低税率 (%8) 或标准税率 (%18) 征税。例如,产品 A = 折扣价 (%8),产品 B = 标准价 (%18)。我可以轻松获得总税额,但我想打印 sperate tax total mounts with tax class.

如何获取订单的总减税金额?也是标准利率。

如何回显它们?

The Tax class is not registered anywhere in the order data… It's registered in each product and optionally for shipping.

您可以简单地使用专用的 WC_Abstract_Order 方法 get_tax_totals() (Woocommerce 用于分隔税行) 并且您将获得税标签百分比在每个税行设置中设置。

费率代码 $rate_code 由 COUNTRY-STATE-NAME-Priority 组成。
例如:GB-VAT-1US-AL-TAX-1.

显示单独税行的代码:

// Get the WC_Order instance Object from the Order ID (if needed)
$order = wc_get_order($order_id);

// Output the tax rows in a table
echo '<table>';
foreach ( $order->get_tax_totals() as $rate_code => $tax ) {
    $tax_rate_id  = $tax->rate_id;
    $tax_label    = $tax->label;
    $tax_amount   = $tax->amount;
    $tax_f_amount = $tax->formatted_amount;
    $compound     = $tax->is_compound;
    echo '<tr><td>' . $tax_label  . ': </td><td>' . $tax_f_amount . '</td></tr>';
}
echo '</table>';

If you want to display something like Reduced rate (%8) or Standart rate (%18), you will have to customize the "Tax name" in the Tax settings for each tax line in each Tax rate (But it will be displayed everywhere and not only in your custom PDF plugin).

此外,税收 class 仅用于设置目的和管理员查看。