I'm trying to get the tax label in WooCommerce for each order item.
For example: 2x Product 1 - 19 % MwSt. (tax) 4x Product 2 - 19 % MwSt. (tax) 1x Product 2 - 19 % MwSt. (tax)
So I added the taxes "19 % (tax)" as standard value and "7 % (Tax)" as reduced tax in the woocommerce settings. I also set that I want to display and type-in prices in WooCommerce "without taxes".
Now I placed an order with these two items (digital and downloadable) and afterwards I try to get the tax values of each order line item.
$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);
}
This is the output:
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" } }
So as this doesn't give me the label of the tax per line item I tried the following:
$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());
}
This is the output:
string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer" string(14) "Mehrwertsteuer"
But it should be "19 % MwSt.".
So I tried this one:
$wc_order = wc_get_order(143);
foreach ($wc_order->get_items(array('tax')) as $item_id => $line_item) {
var_dump($line_item->get_label());
}
This outputs:
string(10) "19 % MwSt."
So yeah, that's the value I need but why does it output this value only one time as I have seven items in the order?
Is there a chance to get the tax label of each order line item or isn't it possible in WooCommerce? My purpose is to create an invoice program but I have to consider if there are different tax rates per line.
WooCommerce Version is 3.4.2
Thanks in advance