Remove "Shipping: FREE" text from the email body

In the Customer Notification email, the placeholder ORDERINFO loads order information along with "Shipping: FREE" text.

Please advise how to remove this text from the email's body.

  • Panos

    Hi Debi ,

    Best way is to filter the email content so this doesn't affect the order meta. For removing that part from the New Order email add the following snippet in a mu-plugin:

    function wpmudev_email_rm_free_shipping( $mail_args ) {
    	remove_filter( 'wp_mail', 'wpmudev_email_rm_free_shipping', 20 );
    
    	if ( is_array( $mail_args ) && isset( $mail_args['message'] ) ) {
    		$mail_args['message'] = str_replace( '<strong>Shipping:</strong> FREE<br />', '', $mail_args['message'] );
    	}
    
    	return $mail_args;
    }
    
    add_action( 'mp_order/new_order', function(){
    	add_filter( 'wp_mail', 'wpmudev_email_rm_free_shipping', 20 );
    } );

    In order to filter the content of the New Order notification and the Order Shipped, here is a more general approach:

    add_action( 'mp_order/new_order', function( $order ){
    	$_REQUEST['action'] = 'mp_new_order';
    	$_REQUEST['post_id'] = $order->ID;
    } );
    
    add_filter( 'wp_mail', function( $mail_args ){
    
    	if (
    		isset( $_REQUEST['action'] ) &&
    		( 'mp_change_order_status' == $_REQUEST['action'] || 'mp_new_order' == $_REQUEST['action'] ) &&
    		isset( $_REQUEST['post_id'] ) && ! empty( $_REQUEST['post_id'] )
    	) {
    		$order_id = (int) $_REQUEST['post_id'];
    		$order = new MP_Order( $order_id );
    		$cart = $order->get_cart();
    
    		if ( $cart->shipping_total() <= 0 ) {
    			if ( is_array( $mail_args ) && isset( $mail_args['message'] ) ) {
    				$mail_args['message'] = str_replace( '<strong>Shipping:</strong> FREE<br />', '', $mail_args['message'] );
    				// Replace other parts if required
    			}
    		}
    	}
    
    	return $mail_args;
    }, 50 );

    Hope this helps :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.