WooCommerce - 使用 php 代码更改订单状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22935358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:22:44  来源:igfitidea点击:

WooCommerce - change order status with php code

phpclassobjectfieldwoocommerce

提问by Pe-Ter

I am trying to change order status in WooCommerce, but I encountered no luck so far. $order instance is created successfully (I know it because echo $order->status;works fine, $order_id is also correct. $order->status = 'pending';simply doesn't change anything, I do not know why.

我正在尝试更改 WooCommerce 中的订单状态,但到目前为止我没有遇到任何运气。$order 实例已成功创建(我知道它因为echo $order->status;工作正常,$order_id 也是正确的。$order->status = 'pending';根本没有改变任何东西,我不知道为什么。

$order = new WC_Order($order_id);
$order->status = 'pending';

Could anyone help me with this?

有人可以帮我解决这个问题吗?

回答by Ratnakar - StoreApps

Try this code:

试试这个代码:

$order = new WC_Order($order_id);
$order->update_status('pending', 'order_note'); // order note is optional, if you want to  add a note to order