Dal*_*ods 2 php wordpress orders email-notifications woocommerce
我想以编程方式发送一封新订单电子邮件,因此它看起来与标准 Woo Commerce 电子邮件模板相同。
\n\n我正在使用 WC_Email_New_Order 类,因此我可以在根据订单对象构造电子邮件之前对其进行调整。
\n\n在一些测试代码中,我现在将其触发 wp_head 挂钩,仅用于测试目的。
\n\nadd_action('wp_head', function() {\n include('wp-content/plugins/woocommerce/includes/emails/class-wc-email.php');\n include('wp-content/plugins/woocommerce/includes/emails/class-wc-email-new-order.php');\n\n $adminEmail = new WC_Email_New_Order();\n\n $id = 1564; // order\n $order = new WC_Order($id);\n\n $adminEmail->trigger( null, $order );\n\n}); \nRun Code Online (Sandbox Code Playgroud)\n\n这部分有效...我收到了主题行正确的电子邮件,但是电子邮件正文只是说...
\n\nYou\xe2\x80\x99ve received the following order from Dave Peterson:\nRun Code Online (Sandbox Code Playgroud)\n\n如何触发电子邮件模板的其余部分?
\n您可以简单地尝试在任何带有动态变量的挂钩函数中使用以下内容$order_id:
// Get the WC_Email_New_Order object
$email_new_order = WC()->mailer()->get_emails()['WC_Email_New_Order'];
// Sending the new Order email notification for an $order_id (order ID)
$email_new_order->trigger( $order_id );
Run Code Online (Sandbox Code Playgroud)
这通常会触发当前订单 ID 的新订单 Woocommerce 通知。
自 WooCommerce 5+ 起: 允许在 WooCommerce 5+ 中重新发送新订单通知