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

如何仅在WooCommerce订单完成邮件通知中移除购买备注

调整方案

你原来的代码没有做邮件类型判断,所以会作用于所有WooCommerce通知邮件。我们可以通过woocommerce_email_order_items_args过滤器传入的邮件对象参数,仅对订单完成邮件做隐藏处理,调整后的代码如下:

add_filter('woocommerce_email_order_items_args','remove_completed_email_order_note', 12, 3);
function remove_completed_email_order_note($args, $order, $email){
    // 仅在客户订单完成邮件中隐藏购买备注
    if ( $email && $email->id === 'customer_completed_order' ) {
        $args['show_purchase_note'] = false;
    }
    return $args;
}

代码说明

  • 给add_filter设置第四个参数为3,是为了获取该过滤器自带的三个入参:配置参数$args、订单对象$order、当前邮件对象$email
  • WoooCommerce默认的客户订单完成邮件ID为customer_completed_order,判断匹配后再修改show_purchase_note的配置值,其他类型邮件的购买备注展示不受影响
  • 代码可直接添加到当前主题的functions.php文件,或自定义功能插件中使用

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 07:45:07