douxian4888 2018-11-25 15:59 采纳率: 0%
浏览 58
已采纳

添加总计不包括 在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
        }
        ?>
  • 写回答

1条回答 默认 最新

  • doww38701 2018-11-25 16:13
    关注

    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:

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化