【发布时间】:2018-11-17 07:30:21
【问题描述】:
我正在尝试在 WooCommerce 中为每个订单项目获取税标签。
例如: 2x 产品 1 - 19 % MwSt。 (税) 4x 产品 2 - 19 % MwSt。 (税) 1x 产品 2 - 19 % MwSt。 (税)
所以我在 woocommerce 设置中添加了税“19 %(税)”作为标准值和“7 %(税)”作为减税。 我还设置了我想在 WooCommerce 中“不含税”显示和输入价格。
现在我下了这两个项目(数字和可下载)的订单,然后我尝试获取每个订单行项目的税值。
$wc_order = wc_get_order(143);
foreach ($wc_order->get_items(array('line_item')) as $item_id => $line_item) {
$order_product_detail = $line_item->get_data();
$item_tax_class = $order_product_detail['tax_class'];
$item_subtotal_tax = $order_product_detail['subtotal_tax'];
$item_total_tax = $order_product_detail['total_tax'];
$item_taxes_array = $order_product_detail['taxes'];
var_dump($item_tax_class);
var_dump($item_subtotal_tax);
var_dump($item_total_tax);
var_dump($item_taxes_array);
}
这是输出:
string(0) "" string(4) "0.76" string(6) "0.2185" array(2) { ["total"]=> array(1) { [1]=> string(6) "0.2185" } ["subtotal"]=> array(1) { [1]=> string(4) "0.76" } } string(0) "" string(4) "0.38" string(6) "0.2451" array(2) { ["total"]=> array(1) { [1]=> string(6) "0.2451" } ["subtotal"]=> array(1) { [1]=> string(4) "0.38" } } string(0) "" string(4) "2.85" string(5) "2.166" array(2) { ["total"]=> array(1) { [1]=> string(5) "2.166" } ["subtotal"]=> array(1) { [1]=> string(4) "2.85" } } string(0) "" string(4) "0.76" string(6) "0.6251" array(2) { ["total"]=> array(1) { [1]=> string(6) "0.6251" } ["subtotal"]=> array(1) { [1]=> string(4) "0.76" } } string(0) "" string(4) "0.95" string(6) "0.8151" array(2) { ["total"]=> array(1) { [1]=> string(6) "0.8151" } ["subtotal"]=> array(1) { [1]=> string(4) "0.95" } } string(0) "" string(4) "1.14" string(6) "1.0051" array(2) { ["total"]=> array(1) { [1]=> string(6) "1.0051" } ["subtotal"]=> array(1) { [1]=> string(4) "1.14" } } string(0) "" string(4) "1.52" string(6) "1.3851" array(2) { ["total"]=> array(1) { [1]=> string(6) "1.3851" } ["subtotal"]=> array(1) { [1]=> string(4) "1.52" } }
因此,由于这没有给我每个订单项的税费标签,我尝试了以下方法:
$wc_order = wc_get_order(143);
foreach ($wc_order->get_items(array('line_item')) as $item_id => $line_item) {
$order_item_tax = new WC_Order_Item_Tax($item_id);
var_dump($order_item_tax->get_label());
}
这是输出:
string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer"
但它应该是“19 % MwSt”。
所以我尝试了这个:
$wc_order = wc_get_order(143);
foreach ($wc_order->get_items(array('tax')) as $item_id => $line_item) {
var_dump($line_item->get_label());
}
这个输出:
string(10) "19 % MwSt."
所以是的,这就是我需要的值,但为什么它只输出一次这个值,因为我的订单中有七件商品?
是否有机会获得每个订单行项目的税标签,或者在 WooCommerce 中不可能? 我的目的是创建一个发票程序,但我必须考虑每行是否有不同的税率。
WooCommerce 版本是 3.4.2
提前致谢
【问题讨论】:
标签: php wordpress woocommerce orders tax