重新排列WooCommerce电子邮件通知中的订单明细总计

时间:2017-12-22 14:18:42

标签: php wordpress woocommerce orders email-notifications

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

enter image description here

我知道这个循环是在woocommerce> templates>电子邮件的“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
                    }
                }
            }

1 个答案:

答案 0 :(得分:2)

使用挂钩在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文件中,或者放在任何插件文件中。

经过测试和工作。

enter image description here

相关问题