将支票付款方式的订单状态更改为“正在处理”;的地位


Change orders status made with cheque payment method to "processing" status

我需要让WooCommerce将支票支付推送到"处理"状态,而不是"等待"状态。我尝试了下面的代码片段,但它似乎没有效果。

下面是我的代码:
add_filter( 'woocommerce_payment_complete_order_status', 'sf_wc_autocomplete_paid_orders' );
function sf_wc_autocomplete_paid_orders( $order_status, $order_id ) {
$order = wc_get_order( $order_id );
if ($order->status == 'on-hold') {
    return 'processing';
}
return $order_status;
}

我怎样才能做到这一点?

谢谢。

这是您正在查看的函数钩子在 woocommerce_thankyou hook:

add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
function cheque_payment_method_order_status_to_processing( $order_id ) {
    if ( ! $order_id )
        return;
    $order = wc_get_order( $order_id );
    // Updating order status to processing for orders delivered with Cheque payment methods.
    if (  get_post_meta($order->id, '_payment_method', true) == 'cheque' )
        $order->update_status( 'processing' );
}

此代码位于您的活动子主题(或主题)的function.php文件或任何插件文件中。

这是测试和工作。


相关主题:WooCommerce:自动完成支付订单(取决于支付方式)

我不想使用Thank You过滤器,以防订单在前一步仍然被设置为On Hold,然后将其更改为我想要的过滤器状态(在我的情况下是自定义状态,或者在您的情况下是Processing)。所以我在支票网关中使用了过滤器:

add_filter( 'woocommerce_cheque_process_payment_order_status', 'myplugin_change_order_to_agent_processing', 10, 1 );
function myplugin_change_order_to_agent_processing($status){
    return 'agent-processing';
}

我希望这能帮助到其他人,让他们知道还有其他的选择。

LoicTheAztec之前的答案已经过时了,并且在直接访问order对象上的对象字段时给出了错误。

正确代码应为

add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
function cheque_payment_method_order_status_to_processing( $order_id ) {
    if ( ! $order_id )
        return;
    $order = wc_get_order( $order_id );
    // Updating order status to processing for orders delivered with Cheque payment methods.
    if (  get_post_meta($order->get_id(), '_payment_method', true) == 'cheque' )
        $order->update_status( 'processing' );
}