使用支票付款方式将订单状态更改为"处理"状态

Dar*_*n47 2 php wordpress orders woocommerce payment-method

我需要通过检查"处理"状态而不是"暂停"状态来进行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;
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

谢谢.

Loi*_*tec 10

这是你正在寻找挂钩woocommerce_thankyou钩子的功能:

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' );
}
Run Code Online (Sandbox Code Playgroud)

此代码位于活动子主题(或主题)的function.php文件中,或者也可以放在任何插件文件中.

这是经过测试和运作的.


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

  • 我很惊讶感谢页面是正确的钩子,但我找不到更好的东西,所以我认为就是这样. (2认同)

Mai*_*Bay 5

我不想使用“谢谢”过滤器,以防订单在上一步中仍设置为“暂停” ,然后再将其在过滤器中更改为我所需的状态(在我的情况下为自定义状态,在您的情况下为“正在处理”)。所以我在检查网关中使用了过滤器:

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';
}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助其他人知道还有另一种选择。