2
votes

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

1 Answers

2
votes

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