Customize WooCommerce orders displayed shipping

I’m using the following code to update the Shipping text on the Cart and Checkout page in WooCommerce

/* Change Text for Shipping message when shipping is $0.00 AND remove the "Shipping" text
*********************************************************************************************/

add_filter( 'woocommerce_cart_shipping_method_full_label', 'add_free_shipping_label', 10, 2 );
function add_free_shipping_label( $label, $method ) {
    if ( $method->cost == 0 ) {
        $label="<strong>$0.00</strong>"; //not quite elegant hard coded string
    } else {
        $label = preg_replace( '/^.+:/', '', $label );
    }
    return $label;
}

It works as it should there but on the Thank You and confirmation emails, it shows the word “Shipping” since shipping is $0.00 (free).

What is the filter for modifying the shipping output on the Thank You and confirmation emails for the Shipping sections?

1 Answer
1

There are mainly 2 filters to be used:

1) the filter woocommerce_order_shipping_to_display located in get_shipping_to_display() method, used by get_order_item_totals() method to display the shipping in order total rows:

add_filter( 'woocommerce_order_shipping_to_display', 'customize_order_shipping_to_display', 10, 3 );
function customize_order_shipping_to_display( $shipping, $order, $tax_display ){
    // Your code to filter displayed shipping

    return $shipping;
}

2) Or filter woocommerce_get_order_item_totals located in get_order_item_totals() method that is used to display the order total rows:

add_filter( 'woocommerce_get_order_item_totals', 'customize_order_item_totals', 10, 3 );
function customize_order_item_totals( $total_rows, $order, $tax_display ){
    // You can make changes below
    $total_rows['shipping']['label'] = __( 'Shipping:', 'woocommerce' ); // The row shipping label
    $total_rows['shipping']['value'] = $order->get_shipping_to_display( $tax_display ); // The row shipping value

    return $total_rows;
}

Code goes in functions.php file of your active child theme (or active theme).

Leave a Comment