Php 在Woocommerce电子邮件通知中将税收总额添加为单独的一行
我想编辑的内容,客户得到后,订购。我想我必须编辑位于wp content/plugins/woocommerce/templates/emails/email-order-details.php的这个文件 使用以下代码:Php 在Woocommerce电子邮件通知中将税收总额添加为单独的一行,php,wordpress,templates,woocommerce,email-notifications,Php,Wordpress,Templates,Woocommerce,Email Notifications,我想编辑的内容,客户得到后,订购。我想我必须编辑位于wp content/plugins/woocommerce/templates/emails/email-order-details.php的这个文件 使用以下代码: <tr> <th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1
<tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ?
'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['label'] ); ?></th>
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : '';
?>"><?php echo wp_kses_post( $total['value'] ); ?></td>
有人知道怎么做吗?如果您想在所有电子邮件通知上进行此更改,您将使用以下代码,该代码将在单独的新行中显示总金额(不显示税费)和税费:
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文件。测试和工作
如果希望仅针对“客户发票”电子邮件通知,则需要更改模板
电子邮件/email order details.php
,通过主题覆盖该模板
请先阅读文档:
将电子邮件/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;
经过测试,也能正常工作……您能帮我解决这个问题吗?
// 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;