更改 Woocommerce 电子邮件 table 总计中的 "Shipping" 标签?

Change "Shipping" label in Woocommerce email table totals?

我正在 WooCommerce 中自定义订单电子邮件模板,需要将 "Shipping" 的标题更改为 "Delivery,",并将 "Shipping address" 更改为 "Delivery address"。我尝试了一个插件 "Say What" 来更改文本,但它没有用。有一个循环处理所有这些信息。

Woocommerce email template

这是"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', 'renaming_shipping_order_item_totals', 10, 3 );
function renaming_shipping_order_item_totals( $total_rows, $order, $tax_display ){
    // Only on emails notifications
    if( ! is_wc_endpoint_url() )
        $total_rows['shipping']['label'] = __('Delivery', 'woocommerce');

    return $total_rows;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。


要将 "Shipping address" 标签更改为 "Delivery address",您需要 copy/edit 模板 email-addresses.php,替换:

_e( 'Shipping address', 'woocommerce' );

作者:

_e( 'Delivery address', 'woocommerce' );

参见:Template structure & Overriding templates via a theme