How do I update the shipping method when creating an order in woocommerce?

I am creating a new order via wc_create_order(), the order gets added to the admin and that works fine, however the part where i have been stuck is adding the shipping method while creating the order. This is the basically what i’m using to create the order

if( !empty( $products ) ) {
                $order_args = array(
                    'customer_id' => $user_ID
                );
                $order = wc_create_order($order_args);

                // get_products with id and next is for quantity
                foreach ($products as $product) {
                    $order->add_product( get_product( $product[prod] ), $product[qty] ); 
                }

                $order->set_address( $billing_address, 'billing' );
                $order->set_address( $shipping_address, 'shipping' );
                $order->calculate_shipping();
                $order->calculate_totals();
            }

So all i need to figure out is how to add a chosen shipping method that has been stored in the user meta for this order. Any help would be appreciated. Thanks! 🙂

Related posts