我正在尝试更改 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();
编辑:更改似乎需要永远才能在管理面板上生效...由于这是通过编程完成的,情况会怎样...或者是否已存储?
最佳答案
我不了解 woocommerce,但认为您应该在每次循环运行时对 item 调用 $item->save()
。
关于php - 在 Woocommerce 3 上的订单中更新并保存订单商品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51956457/