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 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥50 用logisim设计16位单时钟周期cpu
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应
  • ¥15 如何用字典的Key,显示在WPF的xaml中
  • ¥15 weautomate读取Excel表格信息然后填写到网页一直报错,如何解决?
  • ¥15 C#如何在Webview2中获取网页验证码