Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide Shipping Address Based on Shipping Method in Email Notifications?

Depending on how customers want their items shipped, you can adjust the email notifications. If they choose local pickup, there’s no need for a shipping address. The following code will display the shipping address only when a shipping method other than ‘local pickup’ is selected.

function ts_custom_display_shipping_address_in_email( $order, $sent_to_admin, $plain_text, $email ) {
    // ======================> Here begins the customization

    $shipping_local_pickup = false;
    if ( $items_totals = $order->get_order_item_totals() ) {
        foreach ( $items_totals as $items_total ) {
            if ( $items_total['value'] == 'Local Pickup' && ! $shipping_local_pickup ) {
                $shipping_local_pickup = true;
            }
        }
    } // End

}   

add_action( 'woocommerce_email_order_details', 'ts_custom_display_shipping_address_in_email', 10, 4 );

Output

If a customer had chosen ‘local pickup’ during checkout then the shipping address will not be shown in the email notifications.

How to Hide Shipping Address Based on Shipping Method in Email Notifications?

But, if any other shipping method was chosen then the code will show both shipping and billing address on the email notification.

How to Hide Shipping Address Based on Shipping Method in Email Notifications?

Do you want to show the shipping address in all email notifications? Then you can find it here on how to display shipping address in email notifications.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x