【问题标题】:Add the tax total as a separated row on Woocommerce email notifications在 Woocommerce 电子邮件通知中将总税额添加为单独的行
【发布时间】:2019-03-26 12:12:39
【问题描述】:

我想编辑客户在订购后收到的Woocommerce invoice 的内容。我想我必须编辑这个位于 wp-content/plugins/woocommerce/templates/emails/email-order-details.php 的文件

使用以下代码:

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

现在它在与总价相同的规则中显示增值税详细信息,但我希望它位于单独的规则中,如下所示:

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

有人知道怎么做吗?

【问题讨论】:

    标签: php wordpress templates woocommerce email-notifications


    【解决方案1】:

    如果您希望对所有电子邮件通知进行此更改,您将使用以下代码,该代码将在单独的新行中显示总计(不显示税)和税:

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

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。


    如果您希望仅定位“客户发票”电子邮件通知,则需要更改模板 emails/email-order-details.php,通过您的主题覆盖它。

    请先阅读文档:Template structure & Overriding templates via a theme

    将emails/email-order-details.php 模板文件复制到主题文件夹后,打开/编辑它。

    在第 64 行之后:

                $totals = $order->get_order_item_totals(); 
    

    添加以下内容:

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

    经过测试并且也可以工作......

    【讨论】:

    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多