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

问题描述 投票:1回答:1

我想编辑客户订购后获得的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个回答
0
投票

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

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文件中。经过测试和工作。

enter image description here


如果您只想定位“客户发票”电子邮件通知,则需要对模板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;

经过测试和工作......

© www.soinside.com 2019 - 2024. All rights reserved.