How to create a new shipping method in Magento 2


Hi everybody, I am Cuong, Welcome back to my Magento 2 tutorial video series.
Today, I am going to show everybody a best practice, How to create a new shipping method in Magento 2.

By default, Magento 2 provides us some shipping methods as Flat Rate, Free Shipping, Table Rates, UPS, USPS, FedEx, DHL, you can see these shipping methods by going to the Stores → Settings → Configuration → Sales → Shipping Methods.

If you don’t want to use these shipping methods, you can create a new custom shipping method via your requirements, this practice will help you to do it working.

Let’s do this practice, you need to follow steps by step:

Step 1: Declaring a new module called PHPCuong_ShippingExpress
– Create the namespace PHPCuong in the path appcode.
– Create the module named ShippingExpress in the path appcodePHPCuong.
– Create the file named registration.php in the path appcodePHPCuongShippingExpress
– Create the file named module.xml in the path appcodePHPCuongShippingExpressetc

End of the step #1, I have been completed the step to create a new module called PHPCuong_ShippingExpress.

Step 2: Declaring a new shipping method
– Create the new file system.xml in the path appcodePHPCuongShippingExpressetcadminhtml

– Create the new file config.xml in the path appcodePHPCuongShippingExpressetc
This file helps us to set the default value for the new shipping method.

– Create the new file Express.php in the path appcodePHPCuongShippingExpressModelCarrier

Step 3: Test and See the results
Run the commands line following:
php bin/magento setup:upgrade –keep-generated
php bin/magento cache:flush

Go to the backend Stores → Settings → Configuration → Sales → Shipping Methods.
the new shipping method has been created successfully.
Enable this shipping method and test it on the storefront.

Go to the storefront, add a product to the shopping cart and go to the checkout page.

Yeah, it works perfectly.

For now, I try to change the price.

Thank you for your watching. If you have any questions about this practice please feel free to leave a comment below.

Don’t forget to like, comment, share and subscribe to my channel for getting the latest videos.

Please do not hesitate to contact me if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.

Get the source codes of this practice in the Github


Xem thêm bài viết khác:


  1. Thanks for the video.
    it works 100% with me.

    and please help me to find the solution for custom 'table rates' pricing customization method.
    the existing method has only a few options, ['Country'/'Region/StateZip'/'Postal Code'/'Condition'/'Shipping Price']
    I need city selector by 'city' [*], not by 'county' or 'zip/postal-codes' 
    (I going to use this cart for only 1 'country' -> without properly using postal & codes/zip codes)
    shipping rates "Destination vs Price" may vary by a new -> 'city name' can select by 'city name' on dropdown list for easy use.


Please enter your comment!
Please enter your name here