I am trying to set Shipping Method Progrmatically but getting following error. The shipping method is missing. Select the shipping method and try again.

foreach ($quote->getAllAddresses() as $address) {
            // Build grand total.
        $grandTotal = (($finalPrice + $shipping + $tax) - $discount);
        $baseGrandTotal =  $this->convertPrice($grandTotal);
        $baseFinalPrice =  $this->convertPrice($finalPrice);
        $baseDiscount =  $this->convertPrice($discount);
        $baseTax =  $this->convertPrice($tax);

        //$address->setFreeShipping(true); //tried this but not getting set

        $address->setShippingMethod('flatrate_flatrate'); //tried this getting error


  • First, you have to calculate the total then you have to check the available shipping method and then apply Shipping method. – Amit Bera Aug 19 '19 at 13:58

Please update the code like below


Let me know if you need further assistance.

  • Still same error – Sairaj Gadekar Aug 19 '19 at 14:40
  • @ramkrishan if i try to use setshippingmethod and then if i use getshippingmethod the result is empty – Sairaj Gadekar Aug 22 '19 at 9:25

Please update this code :-

 $shippingAddress = $quote->getShippingAddress();


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.