将Woocommerce中的待处理订单状态更改为未付款的管理员付款状态 [英] Change admin payment status back to unpaid for pending order status in Woocommerce

查看:481
本文介绍了将Woocommerce中的待处理订单状态更改为未付款的管理员付款状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Woocommerce中的订单状态更改为处理时,付款状态将设置为已付费:

When Order status in Woocommerce is changed to Processing the payment status is set to paid:

但是订单被意外设置为处理中,并且不应获得已付款状态.现在,当我们再次将状态设置为待处理时,它不会删除文本:

But order was accidentally set to processing and shouldn't have gotten the status paid. Now when we set status to pending again it doesn't remove the text:

订单#1234的详细信息
通过采购订单付款. 2018年9月17日上午9:18支付

Order #1234 details
Payment via Purchase Order. Paid on September 17, 2018 @ 9:18 am

您知道如何将文本更改为更改状态之前的内容吗?

Any idea how to change this text to what is was before status was changed?

推荐答案

使用以下代码将重置(空)付款日期,因此它将删除付款消息.

Use the following code that will reset (empty) paid date, so it will remove the paid message.

因此,每当状态为处理中",已完成"或待定"的订单返回到待处理"状态时,付款日期都会被取消.

So each time that an order that have a status as "processing", "completed" or "On Hold" is passed back to "Pending" status, the paid date will be emtied.

代码:

add_action( 'woocommerce_order_status_changed', 'reset_order_paid_date', 20, 4 );
function reset_order_paid_date( $order_id, $old_status, $new_status, $order ){
    if ( in_array( $old_status, array('on-hold', 'processing', 'completed') ) && $new_status == 'pending' ) {
        $order->set_date_paid(null);
        $order->save();
    }
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

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

要使其对有问题的订单有效,请仅运行以下代码一次,并将其粘贴到 function.php 子主题的文件中.然后浏览您网站的任何页面并将其删除...
(其中123是您必须用订单ID替换的订单ID)

To make it effective for your problematic order, run the following code only once, pasting it on function.php child theme's file. Then browse any page of your web site and remove it…
(where 123 is the order ID that you have to replace by your order ID)

$order = wc_get_order( 123 ); // <== HERE set your order number
$order->set_date_paid(null);
$order->save();


相关: 查看全文

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