You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce新订单邮件如何按配送方式标签隐藏指定自提的收货地址

WooCommerce 新订单邮件指定自提方式隐藏收货地址方案

你可以直接修改你当前重写的emails/email-addresses.php模板,追加配送方式标签匹配逻辑即可,完整修改后的代码如下:

<?php
/**
 * Email Addresses
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates\Emails
 * @version 3.9.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$text_align = is_rtl() ? 'right' : 'left';
$address    = $order->get_formatted_billing_address();
$shipping   = $order->get_formatted_shipping_address();

// 新增逻辑开始:匹配指定自提标签,隐藏收货地址
$hide_shipping = false;
// 遍历订单所有配送方式项
foreach ( $order->get_items( 'shipping' ) as $item ) {
    // 获取配送方式前台显示标签
    $method_label = $item->get_method_title();
    if ( $method_label === 'Pick up at Rockefeller Store' ) {
        $hide_shipping = true;
        break;
    }
}
// 匹配到目标自提时清空收货地址变量,触发原有逻辑不展示地址区块
if ( $hide_shipping ) {
    $shipping = '';
}
// 新增逻辑结束

?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0">
    <tr>
        <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; border:0; padding:0;" valign="top" width="50%">
            <h2><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>

            <address class="address">
                <?php echo wp_kses_post( $address ? $address : esc_html__( 'N/A', 'woocommerce' ) ); ?>
                <?php if ( $order->get_billing_phone() ) : ?>
                    <br/><?php echo wc_make_phone_clickable( $order->get_billing_phone() ); ?>
                <?php endif; ?>
                <?php if ( $order->get_billing_email() ) : ?>
                    <br/><?php echo esc_html( $order->get_billing_email() ); ?>
                <?php endif; ?>
            </address>
        </td>
        <?php if ( $shipping ) : ?>
            <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; padding:0;" valign="top" width="50%">
                <h2><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>

                <address class="address"><?php echo wp_kses_post( $shipping ); ?></address>
            </td>
        <?php endif; ?>
    </tr>
</table>

注意事项

  • 代码中匹配的字符串Pick up at Rockefeller Store需要和你后台配送方式设置的显示标签完全一致,包含大小写、空格、特殊字符,否则会匹配失效
  • 后续如果修改了该自提点的前台显示名称,需要同步修改代码中的匹配字符串
  • 该逻辑仅隐藏目标自提方式的收货地址,其余配送/自提方式的地址展示不受影响

内容的提问来源于stack exchange,提问作者Buttsilio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 18:30:04