Change “Shipping” label in Woocommerce email table totals?

走远了吗. 提交于 2020-06-25 05:56:32

问题


I am customizing the order email template in WooCommerce and need to change the title of "Shipping" to "Delivery," as well as change "Shipping address" to "Delivery address". I tried a plugin, "Say What" that would change the text but it did not work. There is a loop that handles all of this information.

Woocommerce email template

This is the code on line 52 in the "email-order-details.php" page.

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

I assume this is a filter hook, but I am not sure how to use it.

woocommerce_get_order_item_totals

回答1:


It can be done using the following hooked function:

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;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.


To change the "Shipping address" label to "Delivery address" you need to copy/edit the template email-addresses.php, replacing:

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

by:

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

See: Template structure & Overriding templates via a theme



来源:https://stackoverflow.com/questions/50961163/change-shipping-label-in-woocommerce-email-table-totals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!