【问题标题】:Update and save an order item in the order on Woocommerce 3在 Woocommerce 3 上的订单中更新并保存订单项目
【发布时间】:2019-01-28 02:25:39
【问题描述】:

我正在尝试更改 woocommerce 中订单项的数量、小计和总计,但我的代码似乎除了最终总计之外没有任何变化……这是为什么呢? (我要更改的任何订单只有 1 个订单项)

这是我更改订单项详细信息的代码;

$ordernum = 12345; //what I want
$qnty = 30; //or whatever
$subtotal = 10; 
$total = 300; //for show

$order = wc_get_order($ordernum);
foreach( $order->get_items() as $item_id => $item ){
                                $item->set_quantity($qnty);
                                $item->set_subtotal($subtotal); 
                                $item->set_total($total);
                                $item->save();
                }
$order->set_total($total);   
$order->save();

编辑:更改似乎需要很长时间才能在管理面板上生效......因为这是以编程方式完成的......还是被存储了?

【问题讨论】:

  • 对不起,你是对的……你试过 save() 方法吗?
  • @LoicTheAztec 是的,我有。但是在管理面板上显示 woocommerce 表格中的更新的订单需要很长时间......为什么?
  • 很难用您问题中提供的代码和上下文给出一些解释。

标签: php wordpress methods woocommerce orders


【解决方案1】:

我不知道 woocommerce,但认为您应该在每个循环运行 ofc 中的项目上调用 $item->save()

【讨论】:

  • 你是对的!这是需要的。
猜你喜欢
  • 2018-08-09
  • 2020-12-24
  • 2018-11-24
  • 2019-06-21
  • 2017-01-27
  • 2023-03-15
  • 2019-09-08
  • 1970-01-01
  • 2018-03-16
相关资源
最近更新 更多