• Resolved ecomevo

    (@ecomevo)


    I’m trying to copy the shipping from a parent order into the child order. I get the shipping rate out of the parent order just fine, when when I save it, I never see the items in the order object modified. After the order finishes with payment complete, the shipping is still set to default instead of the parent order.

    Here is my code. Is there a mistake in the way I’m trying to set this:

    $shippingRate = array_pop($parentOrder->get_items('shipping'));
    
                            if ($shippingRate) {
                                $order->add_item(new WC_Order_Item_Shipping([
                                    'method_title' => $shippingRate->method_name,
                                    'method_id'    => $shippingRate->method_id,
                                    'instance_id'  => $shippingRate->instance_id,
                                    'total'        => $shippingRate->total,
                                    'total_tax'    => $shippingRate->total_tax,
                                ]));
Viewing 2 replies - 1 through 2 (of 2 total)
  • Might be $order->save(); that is needed.

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Shipping never saves’ is closed to new replies.