Search code examples
phpwordpresswoocommerceemail-notifications

Remove the shipping row from the order table in Woocommerce email notifications


In WooCommerce I am trying to remove the shipping row from the order table in email notifications.

enter image description here


Solution

  • Overriding woocommerce templates via the theme, to remove the shipping row in email notifications can be done easily adding few code to emails/email-order-details.php template.

    Here is an extract starting at line 51. So you will replace all the code beetwen html opening <tfoot> tag and closing</tfoot> tag with the following code:

            <tfoot>
                <?php
                    if ( $totals = $order->get_order_item_totals() ) {
                        $i = 0;
                        foreach ( $totals as $key_total => $total ) {
                            $i++;
                            if( $key_total != 'shipping' ):
                            ?><tr>
                                <th class="td" scope="row" colspan="2" 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:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
                            </tr><?php
                            endif;
                        }
                    }
                    if ( $order->get_customer_note() ) {
                        ?><tr>
                            <th class="td" scope="row" colspan="2" style="text-align:<?php echo $text_align; ?>;"><?php _e( 'Note:', 'woocommerce' ); ?></th>
                            <td class="td" style="text-align:<?php echo $text_align; ?>;"><?php echo wptexturize( $order->get_customer_note() ); ?></td>
                        </tr><?php
                    }
                ?>
            </tfoot>
    

    This is tested and works. So you will get something like (Without the shipping row):

    enter image description here