如果您希望对所有电子邮件通知进行此更改,您将使用以下代码,该代码将在单独的新行中显示总计(不显示税)和税:
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 ){
// Only on emails notifications
if( ! is_wc_endpoint_url() ) {
// Change: Display only the gran total amount
$total_rows['order_total']['value'] = strip_tags( wc_price( $order->get_total() ) );
// Create a new row for total tax
$new_row = array( 'order_tax_total' => array(
'label' => __('BTW:','woocommerce'),
'value' => strip_tags( wc_price( $order->get_total_tax() ) )
) );
// Add the new created to existing rows
$total_rows += $new_row;
}
return $total_rows;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。
如果您希望仅定位“客户发票”电子邮件通知,则需要更改模板 emails/email-order-details.php,通过您的主题覆盖它。
请先阅读文档:Template structure & Overriding templates via a theme
将emails/email-order-details.php 模板文件复制到主题文件夹后,打开/编辑它。
在第 64 行之后:
$totals = $order->get_order_item_totals();
添加以下内容:
// Only Customer invoice email notification
if ( $email->id === 'customer_invoice' ):
// Change: Display only the gran total amount
$totals['order_total']['value'] = strip_tags( wc_price( $order->get_total() ) );
// Create a new row for total tax
$new_row = array( 'order_tax_total' => array(
'label' => __('BTW:','woocommerce'),
'value' => strip_tags( wc_price( $order->get_total_tax() ) )
) );
// Add the new created to existing rows
$totals += $new_row;
endif;
经过测试并且也可以工作......