简体   繁体   中英

Always display shipping address in WooCommerce email notifications

WooCommerce used to show shipping address no matter which shipping method was selected during checkout, if you had to hide the shipping address from emails you had to do a custom job like in "https://stackoverflow.com/questions/38936283/hide-shipping-address-on-local-pickup-in-woocommerce-email-notifications/38937106#38937106" answer thread.

After new updates, WooCommerce hides the shipping address from the order emails if local pickup is selected during checkout. I want to show the shipping address on order emails even if local pickup is chosen, if no shipping address is provided, it should default to billing address (this is what happens if any other shipping method is selected to checkout). No idea where to start on this.


Edit #1:

Discussed with Woocommerce support, the change isn't documented but they were able to guide me where this is coming from. According to them I should be able to use woocommerce_order_needs_shipping_address filter hook and it'll start showing shipping address on order emails even when local pickup is used to checkout.

Any help would be appreciated.

This can be done using one simple line of code:

add_filter( 'woocommerce_order_needs_shipping_address', '__return_true' );

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Here's a filter hook that fixed the issue. This will show shipping address on order emails no matter what shipping method is used to checkout. Add this to functions.php :

function show_ship_add_for_local_pickup( $needs_address, $hide ) {
    $needs_address = true;
    return $needs_address;
}
add_filter( 'woocommerce_order_needs_shipping_address', 'show_ship_add_for_local_pickup', 10, 2 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM