使用税类获取单独订单的税款总额 [英] Get separate Order's tax totals amounts with tax class

查看:71
本文介绍了使用税类获取单独订单的税款总额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我们的部分产品采用减税税率 (%8) 或标准税率 (%18) 征税.例如,产品 A = 降价 (%8),产品 B = 标准费率 (%18).我可以轻松获得总税额,但我想打印带有税种的单独税金总额.

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

我如何分别回显它们?

解决方案

Tax 类未在订单数据中的任何位置注册...它已在每个产品中注册,并且可选择用于运输.

您可以简单地使用专用的 WC_Abstract_Order 方法 get_tax_totals() (作为 Woocommerce 用于分隔税行),您将拥有在每个税行设置中设置的税标签百分比.

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

显示分隔税行的代码:

//从订单 ID 中获取 WC_Order 实例对象(如果需要)$order = wc_get_order($order_id);//输出表格中的税行echo '';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 '
'.$tax_label .':</td><td>'.$tax_f_amount .'</td></tr>';}echo '</table>';

<块引用>

如果您想显示诸如 Reduced rate (%8)Standart rate (%18) 之类的内容,您可以自定义税名"" 在税收设置中针对每个税率中的每个税行(但它会显示在任何地方,而不仅仅是在您的自定义 PDF 插件中).

此外,Tax 类仅用于设置目的和管理员视图.

I'm making personal a PDF invoice plugin for woocommerce.

Some of our products has tax with Reduced rate (%8) or Standart rate (%18). For example, Product A = Reduced rate (%8), Product B = Standart rate (%18). I can get total of tax amount easily but I want to print with sperate tax total amounts with tax class.

How to get total Reduced rate tax amount of an order? Also Standart rate.

How can I echo them separately?

解决方案

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

You can simply use the dedicated WC_Abstract_Order method get_tax_totals() (as Woocommerce uses for separated tax rows) and you will have the tax label percentage that is set in each tax line settings.

The Rate code $rate_code is made up of COUNTRY-STATE-NAME-Priority.
For example: GB-VAT-1 or US-AL-TAX-1.

The code to display separated tax rows:

// 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).

Additionally, the Tax class is just for settings purpose and for admin view.

这篇关于使用税类获取单独订单的税款总额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆