I'd like to create an order programmatically (for an API) and also set shipping method.
I have tried with this code:
$item = new WC_Order_Item_Shipping();
$item->set_method_title( "Flat rate" );
$item->set_method_id( "12" ); // set an existing Shipping method rate ID // was flat_rate:12
$item->set_instance_id( "12" ); // set an existing Shipping method rate ID // was flat_rate:12
//$item->set_total( $new_ship_price ); // (optional)
$order->add_item( $item );
But it has several caveats, for instance; I have to type the method title. I'd like it to just fetch from the shipping methods data already entered in WordPress (e.g. Local Pickup, GLS, etc)