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