2 php wordpress phpmailer woocommerce
我需要在结账后发送这两封电子邮件。
1.- Woocommerce 自动电子邮件(汇总订单、王子、总价等)。
2.- 包含附加信息的电子邮件。
我一直在寻找,但无法通过 WooCommerce 插件做到这一点,而且我无法使用 Shopmagic 等其他插件,所以......它必须使用代码。
经过长时间的搜索,我认为可能是这样的。
(状态控制的顺序是processing和否completed,因为我在Stripe和Stripe中使用测试模式进行测试,在测试模式下,订单被定义为“处理”状态,而不是completed。
我的文件中现在的内容functions.php是:
$order = new WC_Order( $order_id );
function order_processing( $order_id ) {
$order = new WC_Order( $order_id );
$to_email = $order["billing_address"];
$headers = 'From: Your Name <alexiglesiasvortex@gmail.com>' . "\r\n";
wp_mail($to_email, 'subject', '<h1>This is a test for my new pending email.</h1><p>Agree, this is a test</p>', $headers );
}
add_action( 'woocommerce_payment_processing', 'order_processing' );
Run Code Online (Sandbox Code Playgroud)
目前,这不起作用......我没有收到任何错误并且结帐正确结束,但没有新电子邮件到达我的收件箱。
我需要帮助,伙计们,有人可以帮助我吗?非常感谢您,祝您星期一愉快!
woocommerce_payment_processing我在 WooCommerce 文档中找不到任何挂钩。尝试woocommerce_order_status_changed一下。
此外,您访问帐单电子邮件的方式也不正确。$order是一个对象,您无法像数组一样获取帐单电子邮件。您可以使用WC_Orderget_billing_email类的方法。
// send a custom email when the order status changes to "processing"
add_action( 'woocommerce_order_status_changed', 'send_custom_email_order_processing', 10, 4 );
function send_custom_email_order_processing( $order_id, $from_status, $to_status, $order ) {
// only if the new order status is "processing"
if ( $to_status == 'processing' ) {
$to_email = $order->get_billing_email();
$headers = 'From: Your Name <alexiglesiasvortex@gmail.com>' . "\r\n";
wp_mail( $to_email, 'subject', '<h1>This is a test for my new pending email.</h1><p>Agree, this is a test</p>', $headers );
}
}
Run Code Online (Sandbox Code Playgroud)
该代码已经过测试并且可以工作。将其添加到活动主题的functions.php中。