• Resolved mattiasf

    (@mattiasf)


    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)

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I create a WooCommerce order with an existing shipping method?’ is closed to new replies.