How To

How to Get Active Shipping Methods based on Quote ID in Magento 2?

Hello Magento Friends,

Today I have come up with a solution to Get Active Shipping Methods based on Quote ID in Magento 2.

To improve the user experience, you offer various shipping methods in your store. While working with checkout customization, you need a list of active shipping methods. When you want to get active shipping methods for the current quote, you can use the quote ID in Magento 2.

Steps to Get Active Shipping Methods based on Quote ID in Magento 2:

Step 1: Create a helper file Data.php at the below path

app/code/Vendor/Extension/Helper/Data.php

And add the code as follows

<?php
namespace  Vendor\Extension\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function __construct(
        Context $context,
        \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethod)
    {
        $this->shippingMethod = $shippingMethod;
        parent::__construct($context);
    }

    public function getShippingMethod($quoteId){
        $shippinigData = $this->shippingMethod->getList($quoteId);
        $shippingMethod = [];
        foreach($shippinigData as $shipping)
        {
            $shippingMethod [] = $shipping-> getMethodTitle();
        }
        return  $shippingMethod ;
    }
}

Note – From $shippinigData you can also get the Shipping Amount, Shipping Carrier Code, etc.  You can use the getShippingMethod($quoteId) method in your block file or phtml file as per your requirement.

Conclusion:

This way, you can get active shipping methods using quote ID in Magento 2. Share the article with other Magento developers and stay updated for more.

Happy Coding!

Click to rate this post!
[Total: 3 Average: 3.7]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

6 days ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

1 week ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

1 week ago

Top 10 Tips to Hire Shopify Developers

As the world of eCommerce continues to thrive, Shopify has become one of the most…

2 weeks ago

Managing Browser Events and Navigation in Shopify Remix: useBeforeUnload, useHref, and useLocation Hooks

Shopify Remix is an innovative framework that provides a streamlined experience for building fast, dynamic,…

2 weeks ago

Ultimate Guide to Hiring a Top Shopify Development Agency

Building a successful eCommerce store requires expertise, and for many businesses, Shopify has become the…

2 weeks ago