php - 立即在 WooCommerce 中设置待处理订单并发送处理电子邮件通知
问题描述
我需要将所有“暂停”进入的 WooCommerce 订单设置为“正在处理”,并立即发送订单处理电子邮件。
我试过这个
function custom_woocommerce_auto_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
if( 'on-hold'== $order->get_status() ) {
$order->update_status( 'processing' );
}
}
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_order' );
尽管状态发生了变化,但仍会发送“暂停”电子邮件通知,即使它应该只是“处理中”电子邮件通知。
有什么建议吗?
解决方案
只要付款未完成,订单就会处于暂停状态。要将某些付款方式的默认订单状态立即更改为处理(并跳过暂停状态)并发送处理电子邮件通知,您可以使用:
- Bacs -
woocommerce_bacs_process_payment_order_status
过滤钩 - 检查 -
woocommerce_cheque_process_payment_order_status
过滤钩 - 鳕鱼
woocommerce_cod_process_payment_order_status
过滤钩
所以你得到:
function filter_process_payment_order_status( $status, $order ) {
return 'processing';
}
add_filter( 'woocommerce_bacs_process_payment_order_status','filter_process_payment_order_status', 10, 2 );
add_filter( 'woocommerce_cheque_process_payment_order_status','filter_process_payment_order_status', 10, 2 );
add_filter( 'woocommerce_cod_process_payment_order_status', 'filter_process_payment_order_status', 10, 2 );
这些过滤器会导致状态更改为所需的状态。电子邮件通知将基于此自动发送
推荐阅读
- javascript - Odoo 12:如何在 sale.order 模型上单击“保存”按钮时弹出消息?
- c++ - 公开类型的模板模板参数
- facebook-graph-api - 广告系列创建期间的无效展示位置组合 Instagram
- python - 有条件的规范化 Pandas 系列
- c# - C# 将使用动态 linq 的 IEnumerable 函数转换为 IQueryable 函数
- javascript - 单击 window.print() 中的按钮打印所选页面(单击按钮发送页面数)?
- xamarin.android - 如何将静态代码分析[例如 SonarQube ] 与 microsoft App center 集成
- xml - 减去两个值
- mongodb - 与数组聚合时如何提高糟糕的 MongoDB 查询性能
- java - 在 ruby 项目中添加 jruby 后构建失败