添加总计不包括 在Woocommerce电子邮件通知上订购总计的税行
I am looking for a way to add an extra row in my woocommerce order mails, with a subtotal including shipping excluding taxes (or VAT). This row i want to have before the Taxes. (this should be a calculation of the sum of productcosts+shipping costs)
as it's a calculation, it should be something like $get_total_excl_taxes = $order->get_total() - $order->get_total_tax();
I should paste this into the child-theme email-order-details.php i assume. However where I do this, It doesn't work.
Any help would be greatly appreciated.
<?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
}
?>
我正在寻找一种在我的woocommerce订单邮件中添加额外行的方法,其中小计包括不含税的运费 (或增值税)。 这行我想要在税前。 (这应该是产品成本和运费之和的计算) p>
因为它是一个计算,它应该是$ get_total_excl_taxes = $ order-&gt; get_total() - $ order - &gt; get_total_tax(); p>
我应该将其粘贴到我假设的子主题email-order-details.php中。 但是,在我这样做的地方,它不起作用。 p>
任何帮助都将不胜感激。 p>
&lt;?php
$ totals = $ order-&gt; get_order_item_totals();
if if($ totals){
$ i = 0; \ n foreach($ totals as $ total){
$ i ++;
?&gt;
&lt; tr&gt;
&lt; th class =“td”scope =“row”colspan =“2”style =“text -align:&lt;?php echo esc_attr($ text_align);?&gt ;;&lt;?php echo(1 === $ i)?'border-top-width:4px;' :'';?&gt;“&gt;&lt;?php echo wp_kses_post($ total ['label']); ?&gt;&lt; / th&gt;
&lt; td class =“td”style =“text-align:&lt;?php echo esc_attr($ text_align);?&gt ;;&lt;?php echo(1 === $ i)?'border-top-width:4px;' :'';?&gt;“&gt;&lt;?php echo wp_kses_post($ total ['value']); ?&gt;&lt; / td&gt;
&lt; here ??&gt;
&lt; / tr&gt;
&lt;?php
}
}
if($ order-&gt; get_customer_note ()){
?&gt;
&lt; tr&gt;
&lt; th class =“td”scope =“row”colspan =“2”style =“text-align:&lt;?php echo esc_attr($ text_align);?&gt ;;“&gt;&lt;?php esc_html_e('注意:','woocommerce'); ?&gt;&lt; / th&gt;
&lt; td class =“td”style =“text-align:&lt;?php echo esc_attr($ text_align);?&gt ;;”&gt;&lt;?php echo wp_kses_post( wptexturize($ order-&gt; get_customer_note())); ?&gt;&lt; / td&gt;
&lt; / tr&gt;
&lt;?php
}
?&gt;
code> pre>
div>
The following will add a new row with the total excluding VAT in the totals on email notifications:
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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To add this new line before Tax line (when it's enabled in tax settings) use this instead:
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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
You will get something like: