繁体   English   中英

重新排列 WooCommerce 电子邮件通知中的订单详细信息总数

[英]Rearrange order detail totals on WooCommerce email notifications

我正在 WooCommerce 中自定义订单电子邮件模板,并且需要在订单详细信息中将“发货”排在倒数第二,就在“总计”上方。

在此处输入图片说明

我知道这个循环在 woocommerce>templates>emails 的“email-order-details.php”页面的第 52 行,所以在我的孩子主题中设置它,但我不确定从那里去哪里。 这是我正在尝试的:

if ( $totals = $order->get_order_item_totals() ) {
                $i = 0;
                foreach ( $totals as $total ) {
                    $i++;
                    if($total['label'] === "Shipping"){
                        //make second-last above total somehow
                    }
                    else{
                        ?><tr>
                        <th class="td" scope="row" colspan="3" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
                        <td class="td" style="text-align:left; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>" colspan="1"><?php echo $total['value']; ?></td>
                        </tr><?php
                    }
                }
            }

使用挂钩在woocommerce_get_order_item_totals过滤器钩子中的自定义函数,将允许按预期重新排序项目总数:

add_filter( 'woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3 );
function reordering_order_item_totals( $total_rows, $order, $tax_display ){
    // 1. saving the values of items totals to be reordered
    $shipping = $total_rows['shipping'];
    $order_total = $total_rows['order_total'];

    // 2. remove items totals to be reordered
    unset($total_rows['shipping']);
    unset($total_rows['order_total']);

    // 3 Reinsert removed items totals in the right order
    $total_rows['shipping'] = $shipping;
    $total_rows['order_total'] = $order_total;

    return $total_rows;
}

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。

测试和工作。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM