Magento – How to set magento order shipping method

magento-1.9shipping

I am trying to set the shipping merthod in programatically created orders to a custom shipping method, here is a sample of my code…

setTelephone($shipping[Phone]);
// ->setFax($shipping->getFax());

$order->setShippingAddress($shippingAddress)->setShipping_method('flatrate_flatrate');

what am i doing wrong ?

Best Answer

You should set shipping method this way:

// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
    ->collectShippingRates()
    ->setShippingMethod('flatrate_flatrate')
    ->setPaymentMethod('checkmo');

Check this answer for whole order creation

Related Topic