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
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.