Automark ONLY 支付订单到“已完成";WooCommerce 中的状态 3+ [英] Automark ONLY Paid orders to "Completed" status in WooCommerce 3+

查看:88
本文介绍了Automark ONLY 支付订单到“已完成";WooCommerce 中的状态 3+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将刚刚成功支付的订单自动标记为已完成"状态.我在 Stack 和 Google 上搜索了很多,找到了这个答案代码:
WooCommerce:自动完成付费订单(取决于付款)方法)

I would like to automark just success paid orders to "Completed" status. I have searched a lot on Stack and Google, and found this answer code:
WooCommerce: Auto complete paid Orders (depending on Payment methods)

但问题是代码将所有已下订单标记为已完成"状态,而不取决于订单是否成功下达.

But problem is that the code mark all placed orders to "Completed" status not depending if order was success placed or not.

我需要在代码中更改什么才能将仅付费订单自动标记为已完成"状态?

What do I need to change in the code to automark ONLY Paid orders to "Completed" status?

推荐答案

新的增强和简化代码版本 替换(2019 年 3 月):

New enhanced and simplified code version replacement (March 2019):

请参阅:WooCommerce:自动完成付费订单

原答案:

对于 Paypal 和其他第三方网关,要定位的已付款"订单状态为正在处理"(和已完成"),因此您可以将代码轻松更改为:

For Paypal and other third party gateways, the "paid" order status to target is "processing" (and "completed"), so you can lightly change the code to:

add_action( 'woocommerce_thankyou', 'wc_auto_complete_paid_order', 20, 1 );
function wc_auto_complete_paid_order( $order_id ) {

    if ( ! $order_id )
        return;

    // Get an instance of the WC_Product object
    $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;
    // Updated status to "completed" for paid Orders with all others payment methods
    } elseif ( in_array( $order->get_status(), array('on-hold', 'processing') ) ) {
        $order->update_status( 'completed' );
    }
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of the active child theme (or active theme). tested and works.

这样您就可以避免失败"、取消"或待处理"订单.

This way you will avoid "failed", "Cancelled" or "Pending" orders.

这篇关于Automark ONLY 支付订单到“已完成";WooCommerce 中的状态 3+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆