Magento 2 get shipping method from quote

We can get current shipping method selected from quote session in Magento2. We can use object manager or dependency injection to get access the current quote object from session. Let us understand how to get current shipping method applied on cart in Magento2.

Magento 2 get shipping method from quote Example

You can get shipping method from quote using object manager simply as below-

Get Shipping Method in Magento2 Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

$quote = $cart->getQuote();
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();

First get the object manager instance, then load magento checout model cart object to access the quote object. Now using the Quote object you can get the current shipping method from shipping Address object. On the same way you can get other shipping details.

The above example will give you shipping method that user selected during checkout.


Add Comment

📖 Read More