Question

I'm using Magento v 2.3.0.

I am trying to skip Shipping Address section and navigate directly to Payment section if customer has a default address.

I have overridden below class to change the link of checkout url

Magento\Checkout\Block\Onepage\Link

Function overridden

getCheckoutUrl

Now I also use the checkout session in above overridden class to get the quote and set the shipping address in it.

I use tablerate_bestway as shipping method.

How do I set the shipping method and recalculate the shipping rate and save it in the quote?

Was it helpful?

Solution

After set the shipping address in quote use below code to set shipping method programatically

$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
        ->collectShippingRates()
        ->setShippingMethod('shippingMethod') //shipping method
        ->setShippingDescription('shipping method description'); //shipping description
$quote->save();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top