首页 > 解决方案 > 立即在 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' );

尽管状态发生了变化,但仍会发送“暂停”电子邮件通知,即使它应该只是“处理中”电子邮件通知。

有什么建议吗?

标签: phpwordpresswoocommerceordersemail-notifications

解决方案


只要付款未完成,订单就会处于暂停状态。要将某些付款方式的默认订单状态立即更改为处理(并跳过暂停状态)并发送处理电子邮件通知,您可以使用:

  • 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 );

这些过滤器会导致状态更改为所需的状态。电子邮件通知将基于此自动发送


推荐阅读