Вы можете использовать следующее, которое отображает общую сумму налога в отдельной строке ниже общей суммы заказа (для заказов и уведомлений по электронной почте) :
// Add total taxes as a separated line before order total on orders and emails
add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
// Display only the gran total amount
$gran_total = wc_price( $order->get_total() );
$total_rows['order_total']['value'] = is_wc_endpoint_url() ? $gran_total : strip_tags( $gran_total );
$total_tax_amount = wc_price( $order->get_total_tax() );
$total_tax_amount = is_wc_endpoint_url() ? $total_tax_amount : strip_tags( $total_tax_amount );
// Create a new row for total tax
$tax_row = array( 'order_tax_total' => array(
'label' => __('Herav MVA:','woocommerce'),
'value' => $total_tax_amount
) );
$total_rows['order_total']['value'] = $gran_total;
return $total_rows + $tax_row;
}
Или с вашим обычным расчетом 20% налога:
// Add total taxes as a separated line before order total on orders and emails
add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
// Display only the gran total amount
$gran_total = (float) $order->get_total();
$total_rows['order_total']['value'] = is_wc_endpoint_url() ? $total_html : strip_tags( $total_html );
// Custom tax calculation (for 20% tax rate)
$total_tax_amount = wc_price( $gran_total - $gran_total / 1.2 );
$total_tax_amount = is_wc_endpoint_url() ? $total_tax_amount : strip_tags( $total_tax_amount );
// Create a new row for total tax
$tax_row = array( 'order_tax_total' => array(
'label' => __('Herav MVA:','woocommerce'),
'value' => $total_tax_amount
) );
$total_rows['order_total']['value'] = wc_price( $gran_total );
return $total_rows + $tax_row;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы). Проверено и работает.