MrEbabi / Woocommerce-Combine-Orders

PHP Function with two input fields for Order IDs and a button to combine those orders in Woocommerce Admin Order List Page

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Item meta are lost

brambil opened this issue · comments

With your method only item are copied, but item meta are lost (for example form).

I suggest this code:

            $first_order = wc_get_order($first_order_id);
            $second_order = wc_get_order($second_order_id);

            foreach ( $first_order->get_items() as $item_id => $item ) {

              $itemProd = new WC_Order_Item_Product($item_id);
              $itemProd->set_order_id($second_order_id);
              $itemProd->save();

            }

In this way you migrate item from an order to another using Woocommerce methods

this solution is more clever and also shorter. thanks for sharing 🚀