[英]Send customer on-hold order notification once order is placed in Woocommerce 3.3
I have this issue.我有这个问题。 I using Woocommerce 3.3.3 in this moment in my site and noticed one weird issue.
我现在在我的网站上使用 Woocommerce 3.3.3 并注意到一个奇怪的问题。 After customer placed order, their order is stuck on "On Hold" into Woocommerce orders.
客户下订单后,他们的订单被卡在“暂停”状态到 Woocommerce 订单中。
and customer dont get any order confirmation mail.并且客户没有收到任何订单确认邮件。 When go to order and move status on order from "On Hold" to "Processing" customer is getting Order Confirmation mail, that should be automatically.
当转到订单并将订单状态从“暂停”移动到“处理中”时,客户收到订单确认邮件,这应该是自动的。 Searched, and found this " fix ":
搜索,发现这个“修复”:
add_filter( ‘woocommerce_defer_transactional_emails’, ‘__return_false’ );
to be placed into functions.php, but seems that dont changed nothing.被放入functions.php,但似乎没有改变什么。 Anyone with similar issue?
有人有类似问题吗?
Try the following instead:请尝试以下操作:
add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
function new_order_on_hold_notification( $order_id ) {
$order = wc_get_order( $order_id );
// Only for on hold new orders
if( ! $order->has_status('on-hold') )
return; // Exit
// Send Customer On-Hold Order notification
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}
To change "on-hold" paid orders to "processing" use that:要将“暂停”已付款订单更改为“正在处理”,请使用:
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_prrocessing_paid_order', 10, 1 );
function custom_woocommerce_auto_prrocessing_paid_order( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
return;
}
// "Processing" updated status for paid Orders with all others payment methods
else {
if( $order->has_status('on-hold') )
$order->update_status( 'processing' );
}
}
Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 It should work.
它应该工作。
Just to point out:只是要指出:
The solution @LoicTheAztec mentioned works: @LoicTheAztec 提到的解决方案有效:
add_action('woocommerce_new_order', 'new_order_on_hold_notification', 30, 1 );
function new_order_on_hold_notification( $order_id ) {
$order = wc_get_order( $order_id );
// Only for on hold new orders
if( ! $order->has_status('on-hold') )
return; // Exit
// Send Customer On-Hold Order notification
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}
However there's an issue with this solution, at the time woocommerce_new_order
hook is called the order hasn't been fully created yet, so as result in the email notification the order items are not displayed.但是,此解决方案存在一个问题,在调用
woocommerce_new_order
挂钩时,订单尚未完全创建,因此在电子邮件通知中未显示订单项目。 Use the following hook instead:请改用以下钩子:
add_action('woocommerce_checkout_order_processed', 'new_order_on_hold_notification');
function new_order_on_hold_notification( $order_id ) {
$order = wc_get_order( $order_id );
// Only for on hold new orders
if( ! $order->has_status('on-hold') )
return; // Exit
// Send Customer On-Hold Order notification
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger( $order_id );
}
At the time woocommerce_checkout_order_processed
is called the order items are already available for your email.在
woocommerce_checkout_order_processed
被调用时,订单项目已经可用于您的电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.