I'm attempting to use the 'woocommerce_order_shipping_to_display' filter to show 'Free' in the WooCommerce email table when no shipping charges will be incurred. In the image, I'm trying to get the 'Free' and 'Flat Rate' values to just show as free. My PHP is only moderate, but I can't get my code quite there. Does anyone see what I could be missing?

/* return custom text on email when shipping is free */
function filter_email_shipping_text( $shipping ) {
    if ( $this->order_shipping != 0) ) {
      $shipping = __( 'Free!', 'woocommerce' );
      return $shipping;
    } else {
      return $shipping;
add_filter( 'woocommerce_order_shipping_to_display', 'filter_email_shipping_text', 1 );

enter image description here

  • Remove the extra ")" from the 3rd line; it should be: if ( $this->order_shiping != 0 ) {
    – Gabriel
    Oct 12, 2015 at 20:19
  • My mistake with the extra ")". But something else is wrong with my function. It doesn't filter the shipping value and, for some reason, breaks the actual email. When the function is in place, and I resend a processing email, instead of resending, it opens in the same browser window without anything below the main email body table data.
    – Lance
    Oct 13, 2015 at 13:03

1 Answer 1



I was able to fix my function and it now works how intended. This is the working function and filter in case anyone wants to use. This will return custom text when flat rate shipping is free.

/* return custom text on email when shipping is free */
add_filter( 'woocommerce_order_shipping_to_display', 'filter_email_shipping_text', 10, 2 );

function filter_email_shipping_text( $shipping, $order_id ) {
  global $woocommerce, $post;
  $order = new WC_Order( $order_id );
  if ( $order->order_shipping == 0 ) {
    $shipping = sprintf(__( 'Free!', 'woocommerce' ));
  return $shipping;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.