从 Woocommerce 新订单电子邮件中删除 "shipping subtotal"

Remove "shipping subtotal" from Woocommerce's new order emails

我曾尝试取消设置代码,但随后它也删除了总计。我想保留总计并删除运费总计。

<?php
    if ( $totals = $order->get_order_item_totals() ) {
        $i = 0;
        foreach ( $totals as $total ) {
            $i++;
            ?><tr>
                <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
                <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
            </tr><?php
        }
    }
?>

我似乎找不到解决方案。有什么建议吗?

谢谢。

要删除 运费小计 行,请改用此代码:

<?php

if ( $totals = $order->get_order_item_totals() ) {
    $i = 0;
    foreach ( $totals as $total_key => $total ) { // Changed HERE
        $i++;
        if( 'shipping' != $total_key ){ // Added HERE
        ?><tr>
            <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
            <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
        </tr><?php
        } // Added HERE
    }
}

?>

或者你可以使用unset()php函数:

<?php

if ( $totals = $order->get_order_item_totals() ) {
    unset(totals['shipping']) // HERE
    $i = 0;
    foreach ( $totals as $total_key => $total ) { 
        $i++;
        ?><tr>
            <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
            <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
        </tr><?php
}

?>