[英]Show subtotal excl. tax, add subtotal tax as separate row on Woocommerce checkout
[英]Add total excl. tax line to order totals on Woocommerce email notifications
我正在尋找一種在我的 woocommerce 訂單郵件中添加額外行的方法,小計包括不含稅(或增值稅)的運費。 我想在稅收之前擁有這一行。 (這應該是產品成本+運輸成本總和的計算)
因為它是一個計算,所以它應該類似於 $get_total_excl_taxes = $order->get_total() - $order->get_total_tax();
我應該將其粘貼到我假設的子主題 email-order-details.php 中。 但是,在我這樣做的地方,它不起作用。
任何幫助將不勝感激。
<?php
$totals = $order->get_order_item_totals();
if ( $totals ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?>
<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>
<here??>
</tr>
<?php
}
}
if ( $order->get_customer_note() ) {
?>
<tr>
<th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Note:', 'woocommerce' ); ?></th>
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo wp_kses_post( wptexturize( $order->get_customer_note() ) ); ?></td>
</tr>
<?php
}
?>
以下將在電子郵件通知的總計中添加一個新行,其中總計不包括增值稅:
add_filter( 'woocommerce_get_order_item_totals', 'add_order_total_excl_vat_row', 10, 3 );
function add_order_total_excl_vat_row( $total_rows, $order, $tax_display ) {
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
// Set last total row in a variable and remove it.
$gran_total = $total_rows['order_total'];
unset( $total_rows['order_total'] );
// Insert our new row
$total_rows['order_total_ev'] = array(
'label' => __( 'Total Excl. VAT :', 'woocommerce' ),
'value' => wc_price( $order->get_total() - $order->get_total_tax() ),
);
// Set back last total row
$total_rows['order_total'] = $gran_total;
}
return $total_rows;
}
代碼位於活動子主題(或活動主題)的 function.php 文件中。 測試和工作。
要在稅收行之前添加此新行(在稅收設置中啟用時),請改用:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_excl_vat_row', 10, 3 );
function custom_order_total_excl_vat_row( $total_rows, $order, $tax_display ) {
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
$new_total_rows = array();
// Loop through total lines
foreach( $total_rows as $key => $values ){
if( $key === 'tax' ){
$new_total_rows['order_total_et'] = array(
'label' => __( 'Total Excl. VAT :', 'woocommerce' ),
'value' => wc_price( $order->get_total() - $order->get_total_tax() ),
);
}
$new_total_rows[$key] = $values;
}
return $new_total_rows;
}
return $total_rows;
}
代碼位於活動子主題(或活動主題)的 function.php 文件中。 測試和工作。
你會得到類似的東西:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.