Items added to order not showing up?
-
i’m trying to make a plugin that lets you copy items form one order into another
I do the following:
$old_order = wc_get_order($old_order_id); duplicate_line_items($new_order, $old_order); //re-fetch order to make sure changes aren't lost. $new_order = $wc_get_order($new_order->get_id()); $new_order->calculate_totals(); $new_order->save_meta_data(); $new_order->save();
My duplicate_line_items function looks like this:
function duplicate_line_items($source_order, $new_order){ foreach ($source_order->get_items() as $item){ $new_order->add_item($item); } $new_order->apply_changes(); $new_order->save(); }
When I run this code, the items do not display in the admin view of the “new” order (the destination order), nor do they show up in the database (select * from wp_woocommerce_order_items WHERE order_id = <destination order post id>).
I do see that per the
WC_Order::add_item()
docs, “The order item will not persist until save.”, but i am saving the order, several times.Am I missing a step here or something?
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Items added to order not showing up?’ is closed to new replies.