跳到主要内容

WooCommerce 邮件编辑器集成指南

本指南展示了扩展程序如何添加自定义邮件通知,并与 WooCommerce 邮件编辑器集成。 注意: WooCommerce 邮件编辑器目前处于 alpha 阶段。要启用它,请转到 WooCommerce > 设置 > 高级 > 功能,并启用 阻止邮件编辑器 (alpha)

快速开始

  1. 扩展 WC_Email – 通过继承核心 WooCommerce 邮件类,为您的通知创建一个自定义邮件类。
  2. 通过 woocommerce_email_classes 注册 – 将您的新邮件类添加到 WooCommerce,以便它出现在管理员邮件设置中。
  3. 通过块编辑器注册邮件 – 通过将您的邮件 ID 注册到 woocommerce_transactional_emails_for_block_editor 过滤器,以启用块编辑器支持。
  4. 创建块模板 – 设计一个基于块的模板,以确保您的邮件与 WooCommerce 邮件编辑器无缝协作。
  5. 设置触发器 – 定义何时以及在什么条件下发送您的自定义邮件(例如,在特定用户操作或事件发生后)。

1. 创建邮件类

继承 WC_Email 并实现所需的 方法:

class YourPlugin_Custom_Email extends WC_Email {

public function __construct() {
$this->id = 'your_plugin_custom_email';
$this->title = __( 'Custom Email', 'your-plugin' );
$this->customer_email = true;
$this->email_group = 'your-plugin';

$this->template_html = 'emails/your-custom-email.php';
$this->template_plain = 'emails/plain/your-custom-email.php';
$this->template_base = plugin_dir_path( __FILE__ ) . 'templates/';

parent::__construct();
}

public function get_default_subject() {
return __( 'Your custom email subject', 'your-plugin' );
}

public function get_default_heading() {
return __( 'Your custom email heading', 'your-plugin' );
}

public function trigger( $order_id ) {
$this->setup_locale();

if ( $order_id ) {
$order = wc_get_order( $order_id );
$this->object = $order;
$this->recipient = $order->get_billing_email();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

$this->restore_locale();
}

public function get_content_html() {
return wc_get_template_html( $this->template_html, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
) );
}

public function get_content_plain() {
return wc_get_template_html( $this->template_plain, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
) );
}
}

2. 注册邮件

将您的邮件添加到 WooCommerce:

// 将自定义邮件类添加到 WooCommerce 邮件列表中。
function your_plugin_add_email_class( $email_classes ) {
$email_classes['YourPlugin_Custom_Email'] = new YourPlugin_Custom_Email();
return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'your_plugin_add_email_class' );

// 添加自定义邮件组。 只有当 WC_Email 类上未设置 email_group 时才需要此操作。
function your_plugin_add_email_group( $email_groups ) {
$email_groups['your-plugin'] = __( 'Your Plugin', 'your-plugin' );
return $email_groups;
}
add_filter( 'woocommerce_email_groups', 'your_plugin_add_email_group' );

3. 在块编辑器中注册电子邮件

第三方扩展需要明确地将他们的电子邮件纳入块编辑器支持。 这通过将您的电子邮件 ID 注册到 woocommerce_transactional_emails_for_block_editor 过滤器来实现:

/**
* 注册用于块编辑器的自定义事务性电子邮件。
*
* @param array $emails 电子邮件 ID 数组。
* @return array 修改后的电子邮件 ID 数组。
*/
function your_plugin_register_transactional_emails_for_block_editor( $emails ) {
$emails[] = 'your_plugin_custom_email';
return $emails;
}
add_filter( 'woocommerce_transactional_emails_for_block_editor', 'your_plugin_register_transactional_emails_for_block_editor' );

重要: 如果缺少此步骤,您的电子邮件可能仍然出现在电子邮件列表中,但它将不会使用电子邮件编辑器,因为第三方开发者需要明确选择。

注意: 对于第三方扩展,除非您使用 woocommerce_transactional_emails_for_block_editor 过滤器进行选择,否则 WooCommerce 不会创建电子邮件帖子。

开发提示: WooCommerce 会使用一个瞬态缓存电子邮件帖子生成。 在测试或开发时,删除瞬态 wc_email_editor_initial_templates_generated 以强制重新生成帖子。

自定义电子邮件模板帖子生成

您可以在创建电子邮件模板帖子之前,使用 woocommerce_email_content_post_data 过滤器修改电子邮件模板帖子数据。 这允许您在模板生成期间自定义帖子标题、内容、元数据或任何其他帖子数据。

过滤器详情:

属性
钩子名称woocommerce_email_content_post_data
自版本10.5.0
参数$post_data (array), $email_type (string), $email_data (\WC_Email)
返回值array

参数:

  • $post_data (array) – 将传递给 wp_insert_post() 的帖子数据数组。 包含键,例如 post_typepost_statuspost_titlepost_contentpost_excerptpost_namemeta_input
  • $email_type (string) – 电子邮件类型标识符(例如,'customer_processing_order')。
  • $email_data (\WC_Email) – WooCommerce 电子邮件对象。

返回值:

返回修改后的帖子数据数组。 此数组将用于创建电子邮件模板帖子。

示例:修改电子邮件模板文章数据

/**
* 在生成过程中自定义电子邮件模板文章数据。
*
* @param array $post_data 文章数据数组。
* @param string $email_type 电子邮件类型标识符。
* @param \WC_Email $email_data WooCommerce 电子邮件对象。
* @return array 修改后的文章数据。
*/
function your_plugin_customize_email_template_post( $post_data, $email_type, $email_data ) {
// 针对特定电子邮件类型修改文章标题。
if ( 'customer_processing_order' === $email_type ) {
$post_data['post_title'] = __( '自定义订单处理电子邮件', 'your-plugin' );
}

// 修改文章内容(块模板 HTML)。
$post_data['post_content'] = str_replace(
'default content',
'custom content',
$post_data['post_content']
);

// 添加自定义元数据。
$post_data['meta_input']['custom_meta_key'] = 'custom_value';

return $post_data;
}
add_filter( 'woocommerce_email_content_post_data', 'your_plugin_customize_email_template_post', 10, 3 );

重要提示:

  • 您可以修改任何有效的 wp_insert_post() 参数(post_titlepost_contentpost_excerptpost_statuspost_namemeta_input 等)。
  • 始终返回修改后的 $post_data 数组。
  • 在修改 post_content 时,请确保保持有效的块标记。
  • 该过滤器适用于所有电子邮件类型;使用 $email_type 来针对特定电子邮件。

4. 创建初始的阻止模板

创建 templates/emails/block/your-custom-email.php 文件:

模板基础属性: 确保在您的电子邮件类的构造函数中设置 $template_base 属性,使其指向您插件的模板目录。 这允许 WooCommerce 正确地定位和加载您的阻止模板文件。 阻止模板的文件名应与普通模板的文件名相匹配,但使用 block 目录而不是 plain 目录。

<?php
use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer;
defined( 'ABSPATH' ) || exit;
?>

<!-- wp:heading -->
<h2 class="wp-block-heading"><?php printf( esc_html__( 'Hello %s!', 'your-plugin' ), '<!--[woocommerce/customer-first-name]-->' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><?php printf( esc_html__( 'Thank you for your order #%s.', 'your-plugin' ), '<!--[woocommerce/order-number]-->' ); ?></p>
<!-- /wp:paragraph -->

<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
<div class="wp-block-woocommerce-email-content"><?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?></div>
<!-- /wp:woocommerce/email-content -->

提示: 如果您为电子邮件模板使用自定义路径,请使用电子邮件类的 template_block 属性设置阻止模板路径。

电子邮件内容占位符:

BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER 是一个特殊的占位符,当渲染电子邮件时,它会被替换为主要电子邮件内容。 此占位符对于与 WooCommerce 的电子邮件系统集成至关重要,并允许电子邮件编辑器将核心电子邮件内容(例如订单详情、客户信息等)注入到您的自定义模板中。

默认情况下,WooCommerce 使用 通用阻止电子邮件模板 来生成替换此占位符的内容。 当 WooCommerce 处理您的电子邮件模板时,它会根据电子邮件类型和上下文,用适当的电子邮件内容替换此占位符。

如果您的电子邮件需要使用不同的内容,您有两种选择:

使用自定义阻止内容模板:

  1. 设置自定义模板: 在您的电子邮件类的构造函数中,将 $template_block_content 属性设置为指向自定义阻止内容模板:

    $this->template_block_content = 'emails/block/custom-content.php';
  2. 实现自定义逻辑: 在您的电子邮件类中实现 get_block_editor_email_template_content 方法,以提供用于生成内容的自定义逻辑:

    public function get_block_editor_email_template_content() {
    return '<!-- wp:paragraph -->
    <p>Your custom block template content here</p>
    <!-- /wp:paragraph -->';
    }

使用动作钩子: 您可以使用动作钩子 woocommerce_email_general_block_email 在内容模板中执行其他操作。

5. 设置触发器

设置邮件发送的时间,可以通过连接到 WordPress 动作来实现。 您可以在 WooCommerce 事件或您自己的自定义动作上触发邮件:

function your_plugin_trigger_custom_email( $order_id ) {
$emails = WC()->mailer()->get_emails();
$email = $emails['YourPlugin_Custom_Email'];

$email->trigger( $order_id );
}

// 在 WooCommerce 订单完成时触发
add_action( 'woocommerce_order_status_completed', 'your_plugin_trigger_custom_email' );

// 在您的自定义插件动作时触发
add_action( 'your_plugin_custom_action', 'your_plugin_trigger_custom_email' );

常用的 WooCommerce 钩子:

  • woocommerce_order_status_completed - 当订单完成时
  • woocommerce_order_status_processing - 当订单正在处理时
  • woocommerce_new_order - 当创建新订单时
  • woocommerce_customer_created - 当新客户注册时

个性化标签

个性化标签 允许您在邮件中插入动态内容。 它们在您的模板中以 <!--[tag-name]--> 的形式出现,并在发送邮件时被实际值替换。

内置标签

WooCommerce 提供了许多按分类组织的内置个性化标签:

客户标签

  • <!--[woocommerce/customer-email]--> - 客户的 Email 地址
  • <!--[woocommerce/customer-first-name]--> - 客户的 名
  • <!--[woocommerce/customer-last-name]--> - 客户的 姓氏
  • <!--[woocommerce/customer-full-name]--> - 客户的 全名
  • <!--[woocommerce/customer-username]--> - 客户的 用户名
  • <!--[woocommerce/customer-country]--> - 客户的国家

订单标签

  • <!--[woocommerce/order-number]--> - 订单号
  • <!--[woocommerce/order-date]--> - 订单日期 (支持格式参数)
  • <!--[woocommerce/order-items]--> - 订单项目 列表
  • <!--[woocommerce/order-subtotal]--> - 订单 小计
  • <!--[woocommerce/order-tax]--> - 订单 税额
  • <!--[woocommerce/order-discount]--> - 订单 折扣 金额
  • <!--[woocommerce/order-shipping]--> - 订单 运费
  • <!--[woocommerce/order-total]--> - 订单 总金额
  • <!--[woocommerce/order-payment-method]--> - 使用的支付方式
  • <!--[woocommerce/order-payment-url]--> - 订单的支付 URL
  • <!--[woocommerce/order-transaction-id]--> - 交易 ID
  • <!--[woocommerce/order-shipping-method]--> - 使用的运输方式
  • <!--[woocommerce/order-shipping-address]--> - 格式化的收货地址
  • <!--[woocommerce/order-billing-address]--> - 格式化的账单地址
  • <!--[woocommerce/order-view-url]--> - 客户订单查看 URL
  • <!--[woocommerce/order-admin-url]--> - 后台订单编辑 URL
  • <!--[woocommerce/order-custom-field]--> - 自定义订单字段 (需要 key 参数)

网站标签

  • <!--[woocommerce/site-title]--> - 网站标题
  • <!--[woocommerce/site-homepage-url]--> - 主页 URL

商店标签

  • <!--[woocommerce/store-email]--> - 商店 Email 地址
  • <!--[woocommerce/store-url]--> - 商店 URL
  • <!--[woocommerce/store-name]--> - 商店名称
  • <!--[woocommerce/store-address]--> - 商店地址
  • <!--[woocommerce/my-account-url]--> - "我的账户" 网页 URL
  • <!--[woocommerce/admin-order-note]--> - 管理员订单备注

自定义个性化标签

创建您自己的标签,用于插件特定的数据,使用适当的 WooCommerce 钩子:

/**
* 注册用于邮件编辑器中的自定义个性化标签。
*
* @param \Automattic\WooCommerce\EmailEditor\Engine\PersonalizationTags\Personalization_Tags_Registry $registry 注册表。
* @return \Automattic\WooCommerce\EmailEditor\Engine\PersonalizationTags\Personalization_Tags_Registry
*/
function your_plugin_register_personalization_tags( $registry ) {
// 注册自定义字段标签
$custom_field_tag = new \Automattic\WooCommerce\EmailEditor\Engine\PersonalizationTags\Personalization_Tag(
// 编辑器中的显示名称
__( '自定义字段', 'your-plugin' ),
// Token (唯一标识符)
'your-plugin/custom-field',
// 分类,用于分组
__( '您的插件组', 'your-plugin' ),
// 回调函数
'your_plugin_get_custom_field_value',
// 属性 (可选)
array(),
// 要插入的值 (可选 - 默认为 token)
null,
// 此标签适用的帖子类型
array( 'woo_email' )
);
$registry->register( $custom_field_tag );

return $registry;
}

// 返回自定义字段值的回调函数
function your_plugin_get_custom_field_value( $context, $args = array() ) {
$order_id = $context['order']->get_id() ?? 0;
return get_post_meta( $order_id, '_custom_field', true );
}

// 使用适当的 WooCommerce 钩子进行注册
add_filter( 'woocommerce_email_editor_register_personalization_tags', 'your_plugin_register_personalization_tags' );

在模板中的使用: 在您的块模板中使用 <!--[your-plugin/custom-field]-->,它将被替换为您的回调函数返回的值。

要了解更多关于个性化标签的信息,请参阅 woocommerce/email-editor 软件包中的 个性化标签文档

提供用于个性化标签的自定义上下文

使用 woocommerce_email_editor_integration_personalizer_context_data 过滤器,向您的个性化标签提供自定义上下文数据。 当您的扩展需要传递额外的 数据(例如,订阅 详情、忠诚度积分或自定义 订单数据),以便您的个性化标签回调函数可以 访问 时,这非常有用。

过滤器 详情

属性价值
钩子 名称woocommerce_email_editor_integration_personalizer_context_data
自版本10.5.0
参数$context (array), $email (\WC_Email)
返回值array

参数

  • $context (array) – 现有的上下文 数据 数组。 数组可能已经包含来自 WooCommerce 核心或其它扩展的 数据
  • $email (\WC_Email) – 正在处理的 WooCommerce 邮件对象。 您可以使用它来 访问 邮件 ID、收件人以及与邮件关联的对象(例如,订单 或客户)。

返回值:

返回一个包含自定义上下文 数据 以及 Woo 核心上下文 数据 的数组。 此数组将通过 $context 参数 提供给所有个性化标签回调函数。

示例:向上下文添加 订阅 数据

/**
* 为个性化标签添加与 *订阅* 相关的上下文 *数据*。
*
* @param array $context 现有的上下文 *数据*。
* @param \WC_Email $email WooCommerce 邮件对象。
* @return array 修改后的上下文 *数据*。
*/
function your_plugin_add_subscription_context( $context, $email ) {
// 仅为与 *订阅* 相关的邮件添加上下文。
if ( strpos( $email->id, 'subscription' ) === false ) {
return $context;
}

// 从邮件对象获取 *订单*。
$order = $email->object instanceof WC_Order ? $email->object : null;

if ( ! $order ) {
return $context;
}

// 将您的自定义 *订阅* *数据* 添加到上下文。
$context['subscription_id'] = $order->get_meta( '_subscription_id' );
$context['subscription_end_date'] = $order->get_meta( '_subscription_end_date' );
$context['renewal_count'] = (int) $order->get_meta( '_renewal_count' );

return $context;
}
add_filter( 'woocommerce_email_editor_integration_personalizer_context_data', 'your_plugin_add_subscription_context', 10, 2 );

示例:在个性化标签的回调函数中使用自定义上下文

一旦您向上下文添加了自定义数据,您的个性化标签回调函数就可以访问它:

/**
* 使用自定义上下文数据的个性化标签回调函数。
*
* @param array $context 上下文数据(包含您的自定义数据)。
* @param array $args 可选的传递给标签的属性。
* @return string 个性化的值。
*/
function your_plugin_get_subscription_end_date( $context, $args = array() ) {
// 访问通过过滤器添加的自定义上下文数据。
$end_date = $context['subscription_end_date'] ?? '';

if ( empty( $end_date ) ) {
return __( 'N/A', 'your-plugin' );
}

// 根据网站设置格式化日期。
return date_i18n( get_option( 'date_format' ), strtotime( $end_date ) );
}

重要提示:

  • 该过滤器在电子邮件个性化期间被调用,因此当处理个性化标签时,您的上下文数据是可用的。
  • 在向上下文添加数据之前,始终检查电子邮件类型是否相关,以避免不必要的处理。
  • 为您的上下文数据使用唯一的键,以防止与 WooCommerce 核心或其他扩展程序发生冲突。
  • $email->object 属性通常包含与电子邮件相关的对象(例如,对于订单电子邮件,是 WC_Order;对于与用户相关的电子邮件,是 WP_User)。
  • 在使用个性化标签中的上下文数据时,请确保根据输出上下文进行适当的转义(例如,esc_html()esc_attr()esc_url())。

完整示例

以下是一个忠诚度计划欢迎邮件实现的示例:

邮件类:

class YourPlugin_Loyalty_Welcome_Email extends WC_Email {
public function __construct() {
$this->id = 'loyalty_welcome_email';
$this->title = __( '忠诚度计划欢迎邮件', 'your-plugin' );
$this->customer_email = true;
$this->email_group = 'loyalty';

$this->template_html = 'emails/loyalty-welcome.php';
$this->template_plain = 'emails/plain/loyalty-welcome.php';
$this->template_block = 'emails/block/loyalty-welcome.php';
$this->template_base = plugin_dir_path( __FILE__ ) . 'templates/';

parent::__construct();
}

public function get_default_subject() {
return __( '欢迎加入我们的忠诚度计划!', 'your-plugin' );
}

public function trigger( $customer_id, $points_earned = 0 ) {
$this->setup_locale();
$customer = new WC_Customer( $customer_id );
$this->object = $customer;
$this->recipient = $customer->get_email();

if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
$this->restore_locale();
}

public function get_content_html() {
return wc_get_template_html( $this->template_html, array(
'customer' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
) );
}

public function get_content_plain() {
return wc_get_template_html( $this->template_plain, array(
'customer' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
) );
}
}

块邮件:

<!-- wp:heading -->
<h2 class="wp-block-heading"><?php printf( esc_html__( '欢迎 %s!', 'your-plugin' ), '<!--[woocommerce/customer-first-name]-->' ); ?></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><?php esc_html_e( '感谢您加入我们的忠诚度计划!', 'your-plugin' ); ?></p>
<!-- /wp:paragraph -->

<!-- wp:woocommerce/email-content {"lock":{"move":false,"remove":true}} -->
<div class="wp-block-woocommerce-email-content"><?php echo esc_html( BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER ); ?></div>
<!-- /wp:woocommerce/email-content -->

注册和设置:

这段代码将所有内容联系起来 - 注册邮件类、模板和触发器:

如何工作:

  1. 邮件注册 使得您的邮件出现在 WooCommerce > 设置 > 邮件 中。
  2. 块编辑器注册 允许您的邮件与 WooCommerce 邮件编辑器一起工作。
  3. 模板注册 允许您注册额外的邮件模板,以便在块编辑器中使用和编辑。
  4. 触发器设置 自动在客户加入您的忠诚度计划时发送邮件。

详细步骤:

  1. 注册邮件:

    • 通过 woocommerce_email_classes 过滤器,将自定义邮件类添加到 WooCommerce 邮件列表中。
    • 通过 woocommerce_email_groups 过滤器,将自定义邮件分组添加到 WooCommerce 邮件分组中。
    • 通过 woocommerce_transactional_emails_for_block_editor 过滤器,将自定义邮件注册到块编辑器中。
  2. 设置模板:

    • 创建 Email Template,并将其添加到 Templates 目录中。
    • Settings 中配置 Email TemplateAuto 发送选项。
  3. 启用和配置:

    • SettingsEnable 您的邮件功能。
    • Allow 用户 RegisterJoin 您的计划。
    • 配置 Welcome 邮件的 Setup,包括主题和正文。
  4. 发送邮件:

    • 使用 Send 功能发送 Mail
    • 您可以选择 Auto 发送,或者手动 Edit 和发送。

示例代码:

// Add the custom email class to the WooCommerce Emails.
add_filter( 'woocommerce_email_classes', function( $classes ) {
$classes['YourPlugin_Loyalty_Welcome_Email'] = new YourPlugin_Loyalty_Welcome_Email();
return $classes;
} );

// Add the custom email group.
add_filter( 'woocommerce_email_groups', function( $email_groups ) {
$email_groups['loyalty'] = __( 'Loyalty Program', 'your-plugin' );
return $email_groups;
} );

// Register the email with the block editor.
add_filter( 'woocommerce_transactional_emails_for_block_editor', function( $emails ) {
$emails[] = 'loyalty_welcome_email';
return $emails;
} );

// Set up trigger - when to send the email
add_action( 'your_plugin_customer_joined_loyalty', function( $customer_id, $points_earned ) {
$emails = WC()->mailer()->get_emails();
$email = $emails['YourPlugin_Loyalty_Welcome_Email'];

$email->trigger( $customer_id, $points_earned );
}, 10, 2 );

常见问题:

  • 邮件没有显示在 Settings 中: 检查 Email registration 是否正确配置。
  • 邮件无法在块编辑器中使用: 检查 Block editor registration 是否正确配置。
  • 邮件没有自动发送: 检查 Trigger setup 是否正确配置,以及触发条件是否满足。
  • 无法 Edit 邮件内容: 确保您已注册 Email Template,并且可以访问 Templates 目录。

其他说明:

  • 您可以使用 New 邮件 Class 来创建自定义邮件。
  • 您可以使用 Edit 功能来修改现有的 Email Template
  • 您可以使用 Lock 功能来防止用户修改某些 Settings
  • and 更多信息,请参考 WooCommerce 的官方文档。

最佳实践

  • 清洗输入并转义输出: 始终验证和清洗在邮件逻辑中使用的任何数据,并在模板中转义输出,以防止安全问题和显示问题。
  • 在各种邮件客户端进行测试: 邮件布局在不同的客户端可能看起来不同。 使用诸如 Litmus 或 Email on Acid 之类的工具,可以帮助您在流行的客户端(例如 Gmail、Outlook 和 Apple Mail)中测试您的邮件,以确保它们看起来符合预期。
  • 使用高效的查询并缓存数据: 在获取用于邮件的数据时,请使用优化的查询,并在可能的情况下缓存结果,以避免降低网站速度。
  • 遵循 WordPress 编码规范: 编写符合 WordPress 规范的代码,以提高可读性和兼容性。
  • 包含适当的错误处理: 添加检查和错误处理,以便在出现问题(例如缺少数据或发送失败)时能够轻松地检测和调试。

故障排除

  • 邮件未显示在管理后台? 仔细检查您的邮件类是否已通过 woocommerce_email_classes 过滤器注册,并且类名是否正确。
  • 邮件未使用块模板或邮件编辑器? 确保您已通过 woocommerce_transactional_emails_for_block_editor 过滤器注册您的邮件 ID。
  • 模板未加载? 确保模板文件路径正确,并且您已将其注册到邮件编辑器中。
  • 标签无法工作? 确认您的个性化标签回调已注册,并且正在返回预期的值。
  • 邮件未发送? 检查邮件是否已在 WooCommerce 设置中启用,并且您的触发操作是否按预期执行。