Use code MAG25 to get $25 off! Limited time offer on Cloudways Magento hosting.
AVAIL NOW

How to Create Custom Shipping Module and Method in Magento 2

Transporting an item from one place to another is called Shipping, and to deliver an ordered product through a medium to your customer is called the Shipping Method.

Magento 2 already has built-in Shipping methods, but if you need custom Shipping Methods, then you have to create a custom Shipping Method. In this guide I am going to show you how to create a custom shipping module in Magento 2.

If you are not familiar with custom module, then first learn about it from this guide: Create Module in Magento 2.

Steps to Follow:

  • Registration and Configuration of Module
  • Create New Fields in Admin Panel
  • Define Shipping Model
  • Create Shipping Model
  • Run Commands

Registration and Configuration of Shipping Module

First of all, configuration and registration of a custom module is required. Let’s first configure and then register the module.

Create module.xml in app/code/Magenticians/Moduleshipping/etc and add the following code in it to configure the module:

Create registration.php in app/code/Magenticians/Moduleshipping and add the following code in it to register the module:

Create New Fields in Admin Panel

Create system.xml in app/code/Magenticians/Moduleshipping/etc/adminhtml and add this code to it:

Define Shipping Model

Now define the shipping model by creating config.xml in app/code/Magenticians/Moduleshipping/etc, add this code to it:

Create Shipping Model Class

In the previous step I defined the Shipping Model class and now I am going to create it by creating Customshipping.php in app/code/Magenticians/Moduleshipping/Model/Carrier. Let’s add this code to it:

Run Commands

Great, you’re all done! Launch your SSH terminal and connect it to your store, and run the following commands in the root directory of your store:

Now let’s check out the result!

First, go to STORES → Configuration from the admin panel of your store. Then click on Shipping Methods under the SALES tab.

magento shipping method

Here, you will see the new shipping Method section: Magenticians Custom Shipping. Enable the Custom Shipping method and set its values according to your need.

magento custom shipping method

Now go to the checkout page of your Magento 2 store and you will see the Magenticians Custom Shipping Method.

Select Custom shipping method

Review and Payments- Custom shipping method

Wrapping Up

After following this guide, you should be able to create a custom shipping method module in Magento 2. Hopefully, all the steps mentioned above were easy to follow and you didn’t get stuck anywhere. However, if you still have any issues or confusions, just leave your thoughts below!

About Author

Syed Muneeb Ul Hasan is an expert in PHP and Magento, he prefers to educate users in implementing and learning Magento. When not working, he loves to watch cricket.

  • Marilena

    Hi there. I am trying to recreate the shipping module according to your instructions for my M2 website. I am confused in this step: Define Shipping Model

    Haven’t we created the config.xml on the first step? Do I just ammend the code or are they 2 separate config.xml files?
    Looking forward to your reply, really interested in making this work.

    • Hello,

      Thanks for highlighting.Well, in the first step module.xml have to be created. I have updated it.

  • ifski

    I want to print shipping labels ? for an order can I do this with this module if not what is the write way to follow for that

  • Julio

    When i go to the payment it shows “Please specify a shipping method”