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

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

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题