Tips on how to present tax share for every merchandise so as in an xml. i create xml when order is paid. however want to point out merchandise tax labels for every gadgets for instance. "7% Mswt", "19% Mswt".
perform get_line_items( $order ) {
$gadgets = [];
/** @var WC_Order_Item_Product $line_items */
$line_items = $order->get_items( 'line_item' );
// loop by means of every merchandise so as
foreach ( $line_items as $item_id => $merchandise ) {
// get the product
/** @var WC_Product $product */
$product = $item->get_product();
// instantiate line merchandise meta
$meta_data = $item->get_formatted_meta_data( '_', true );
$display_meta = [];
foreach ( $meta_data as $meta ) {
$display_meta[] = "{$meta->display_key}: {$meta->display_value}";
}
$item_meta = implode( ', ', $display_meta );
// take away all HTML
$item_meta = wp_strip_all_tags( $item_meta );
// strip HTML in legacy format - observe: in fashionable codecs,
// SV_WC_Helper::array_to_xml will routinely escape HTML and newlines by wrapping
// the contents of the tag in CDATA when obligatory
if ( 'legacy' === $this->export_format ) {
// take away management characters
$item_meta = str_replace( [ "r", "n", "t" ], '', $item_meta );
}
// take away any html entities
$item_meta = preg_replace( '/&(?:[a-z,A-Z,0-9]+|#d+|#x[0-9a-f]+);/', '', $item_meta );
$item_data = [];
$item_data['Id'] = $item_id;
$item_data['Name'] = html_entity_decode( $product ? $product->get_title() : $merchandise['name'], ENT_NOQUOTES, 'UTF-8' );
$item_data['ProductId'] = $product ? $product->get_id() : ''; // dealing with for completely deleted product
$item_data['SKU'] = $product ? $product->get_sku() : ''; // dealing with for completely deleted product
$item_data['Quantity'] = $merchandise['qty'];
$item_data['Price'] = $this->format_decimal( $order->get_item_total( $merchandise ), 2 );
$item_data['Subtotal'] = $this->format_decimal( $order->get_line_subtotal( $merchandise ), 2 );
//$item_data['SubtotalTax'] = $this->format_decimal( $merchandise['line_subtotal_tax'], 2 );
$item_data['Total'] = $this->format_decimal( $order->get_line_total( $merchandise ), 2 );
$item_data['TaxPercentage'] = $merchandise ->get_tax_class()->labels;
$item_data['TotalTax'] = $this->format_decimal( $order->get_line_tax( $merchandise ), 2 );
//$item_data['Refunded'] = $this->format_decimal( $order->get_total_refunded_for_item( $merchandise ), 2 );
//$item_data['RefundedQuantity'] = $order->get_qty_refunded_for_item( $item_id );
/*if ( 'sure' === get_option( 'woocommerce_calc_taxes' ) && 'sure' === get_option( 'woocommerce_prices_include_tax' ) ) {
$item_data['PriceInclTax'] = $this->format_decimal( $order->get_item_total( $merchandise, true ), 2 );
$item_data['TotalInclTax'] = $this->format_decimal( $order->get_line_total( $merchandise, true ), 2 );
}*/
$item_data['Meta'] = $item_meta;
//$item_data['Taxes'] = $this->get_tax_details( $merchandise );
// Preserve order gadgets backwards-compatible with legacy model
if ( 'legacy' === $this->export_format ) {
// rename fields to be appropriate with pre 2.0.0
$item_data['ItemName'] = $item_data['Name'];
$item_data['LineTotal'] = $item_data['Total'];
if ( 'sure' === get_option( 'woocommerce_calc_taxes' ) && 'sure' === get_option( 'woocommerce_prices_include_tax' ) ) {
$item_data['LineTotalInclTax'] = $item_data['TotalInclTax'];
}
// take away knowledge that wasn't current pre 2.0.0
unset( $item_data['Id'], $item_data['Name'], $item_data['ProductId'], $item_data['Subtotal'], $item_data['SubtotalTax'], $item_data['Total'], $item_data['TotalTax'], $item_data['Refunded'], $item_data['RefundedQuantity'], $item_data['TotalInclTax'], $item_data['Taxes'] );
}
/**
* Permit actors to switch the road merchandise knowledge / format
*
* In 2.0.0 renamed from `wc_customer_order_xml_export_suite_order_export_line_item_format`
* to `wc_customer_order_xml_export_suite_order_line_item`
*
* @since 5.0.0
*
* @param array $item_data
* @param WC_Order $order Associated order
* @param array $merchandise Order line merchandise
*/
$gadgets['OrderLineItem'][] = apply_filters( 'wc_customer_order_export_xml_order_line_item', $item_data, $order, $merchandise );
}
return ! empty( $gadgets ) ? $gadgets : null;
}