更改 Woocommerce 中某些特定电子邮件通知的电子邮件主题

Gor*_*ore 1 php wordpress subject email-notifications woocommerce

我想标准化电子邮件主题的结构(对于所有 Woocommerce 电子邮件通知)。\n我正在使用这里所有可用的过滤器

\n\n

但是 \xe2\x80\x9cOnhold\xe2\x80\x9d、\xe2\x80\x9cCancelled\xe2\x80\x9d、\xe2\x80\x9cRefunded\xe2\x80\x9d 和 \xe2\x80\x9cFailed 订单又如何呢\xe2\x80\x9d 电子邮件主题?
\n有没有办法更改这些电子邮件的电子邮件主题?

\n

Loi*_*tec 5

在具有正确过滤器挂钩的 4 个挂钩函数下方,您可以自定义 \xe2\x80\x9cOnhold\xe2\x80\x9d、\xe2\x80\x9cCancelled\xe2\x80\x9d、\xe2 的电子邮件主题\x80\x9c已退款\xe2\x80\x9d 和\xe2\x80\x9c订单失败\xe2\x80\x9d 通知:

\n\n
add_filter( \'woocommerce_email_subject_customer_on_hold_order\', \'customizing_on_hold_email_subject\', 10, 2 );\nfunction customizing_on_hold_email_subject( $formated_subject, $order ){\n    return __("This is the custom on hold order email notification subject", "woocommerce");\n}\n\nadd_filter( \'woocommerce_email_subject_cancelled_order\', \'customizing_cancelled_email_subject\', 10, 2 );\nfunction customizing_cancelled_email_subject( $formated_subject, $order ){\n    return __("This is the custom on cancelled email notification subject", "woocommerce");\n}\n\nadd_filter( \'woocommerce_email_subject_customer_refunded_order\', \'customizing_refunded_email_subject\', 10, 2 );\nfunction customizing_refunded_email_subject( $formated_subject, $order ){\n    return __("This is the custom on refunded email notification subject", "woocommerce");\n}\n\nadd_filter( \'woocommerce_email_subject_failed_order\', \'customizing_failed_email_subject\', 10, 2 );\nfunction customizing_failed_email_subject( $formated_subject, $order ){\n    return __("This is the custom on failed email notification subject", "woocommerce");\n} \n
Run Code Online (Sandbox Code Playgroud)\n\n

代码位于活动子主题(或活动主题)的 function.php 文件中。

\n\n

经过测试并有效。

\n\n
\n

您可以使用WC_Order对象参数$order通过动态订单数据自定义主题\xe2\x80\xa6

\n\n

例如 (具有动态订单 ID 和订单格式修改日期)

\n\n
add_filter( \'woocommerce_email_subject_cancelled_order\', \'customizing_cancelled_email_subject\', 10, 2 );\nfunction customizing_cancelled_email_subject( $formated_subject, $order ){\n    $modified = $order->get_date_modified(); // Get date modified WC_DateTime object\n    return sprintf( __(\'Order #%d  was cancelled on %s\', \'woocommerce\'), $order->get_id(), $modified->date_i18n( \'l jS \\of F Y \\a\\t h:i:s A\' ) );\n}\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

相关:更改 Woocommerce 3 中自定义订单状态的电子邮件主题

\n