dousi5358 2018-10-22 12:09
浏览 77

在Woocommerce电子邮件通知中将税总额添加为单独的行

I would like to edit the contents of the Woocommerce invoice that a customers gets after ordering. I think I have to edit this file located at wp-content/plugins/woocommerce/templates/emails/email-order-details.php

Using the following code:

<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>

Now it shows the VAT details on the same rule as the total price, but I would like it to be on a separate rule as follows:

Totaal: €50,00
BTW:    €8,68

Does anyone know how to do this?

  • 写回答

1条回答 默认 最新

  • dpfw3607 2018-10-22 14:47
    关注

    If you want to have this change on all email notifications, you will use the following code, that will display the gran total (without displayed taxes) and the taxes in a separated new row:

    add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
    function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
        // Only on emails notifications
        if( ! is_wc_endpoint_url() ) {
    
            // Change: Display only the gran total amount
            $total_rows['order_total']['value'] = strip_tags( wc_price( $order->get_total() ) );
    
            // Create a new row for total tax
            $new_row = array( 'order_tax_total' => array(
                'label' => __('BTW:','woocommerce'),
                'value' => strip_tags( wc_price( $order->get_total_tax() ) )
            ) );
    
            // Add the new created to existing rows
            $total_rows += $new_row;
        }
    
        return $total_rows;
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    enter image description here


    If you want to target only the "Customer invoice" email notification, instead you will need to make changes on the template emails/email-order-details.php overriding it through your theme.

    Please read first the documentation: Template structure & Overriding templates via a theme

    Once you have copied emails/email-order-details.php template file to your theme's folder, open/edit it.

    On line 64 after:

                $totals = $order->get_order_item_totals(); 
    

    Add the following:

                // Only Customer invoice email notification
                if ( $email->id === 'customer_invoice' ):
    
                // Change: Display only the gran total amount
                $totals['order_total']['value'] = strip_tags( wc_price( $order->get_total() ) );
    
                // Create a new row for total tax
                $new_row = array( 'order_tax_total' => array(
                    'label' => __('BTW:','woocommerce'),
                    'value' => strip_tags( wc_price( $order->get_total_tax() ) )
                ) );
    
                // Add the new created to existing rows
                $totals += $new_row;
    
                endif;
    

    Tested and works too…

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等