小编Jus*_*ode的帖子

WooCommerce:添加自定义订单状态和自定义电子邮件通知

使用添加在 WooCommerce 4+ 答案代码中发送电子邮件通知的新订单状态,我已经能够收到一个自定义状态的电子邮件通知,但无法了解如何发送电子邮件通知两种自定义状态。

请参阅下面的示例代码和我尝试过的多个自定义状态电子邮件通知的代码。我还包含了完整的代码,它显示了创建多个状态的整个过程。

希望对这个快速修复有所帮助!

另外,至于电子邮件正文 - 是否有可能通过此代码更改处理订单内容,而无需创建新的电子邮件模板?

正在运行 - 单个自定义状态电子邮件通知“已发货”

add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
    $actions[] = 'woocommerce_order_status_wc-shipped';
    return $actions;
}
// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'shipped_status_custom_notification', 10, 4);
function shipped_status_custom_notification( $order_id, $from_status, $to_status, $order ) {
    if(  'shipped' === $to_status ) {
        // The email notification type
        $email_key   = 'WC_Email_Customer_Processing_Order';
        // Get specific WC_emails object
        $email_obj = WC()->mailer()->get_emails()[$email_key];
        // Sending …
Run Code Online (Sandbox Code Playgroud)

php wordpress orders woocommerce hook-woocommerce

5
推荐指数
1
解决办法
2609
查看次数

标签 统计

hook-woocommerce ×1

orders ×1

php ×1

woocommerce ×1

wordpress ×1