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: 2 Average: 5]
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

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

11 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

4 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

7 days ago