2

I am trying to change the quantity, subtotal and total of a line item in woocommerce, but my code seems to not change anything but the end total... why is that?? (there is only 1 line item for any order I want to change)

here is my code to change a line item details;

$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();

EDIT: it seems to take forever for the changes to take effect on the admin panel... what would be the case since this is done programmatically... or is it stored?

RickMorty
  • 73
  • 1
  • 11

1 Answers1

2

I don't know woocommerce but think that you should call $item->save() on item in each loop run ofc.

arczinosek
  • 139
  • 5