【问题标题】:Rearrange order detail totals on WooCommerce email notifications重新排列 WooCommerce 电子邮件通知上的订单详细信息总计
【发布时间】:2018-06-05 04:41:02
【问题描述】:

我在 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
                    }
                }
            }

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

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

    经过测试并且有效。

    【讨论】:

    猜你喜欢
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 2021-12-20
    • 2018-07-27
    • 2019-08-24
    • 1970-01-01
    相关资源
    最近更新 更多