Magento 2 Module


How to create a new shipping method in Magento 2


Hide/Show description

Hi everybody, I am Cuong, Welcome back to my Magento 2 tutorial video series. #magento2tutorial 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 app\code. - Create the module named ShippingExpress in the path app\code\PHPCuong. - Create the file named registration.php in the path app\code\PHPCuong\ShippingExpress - Create the file named module.xml in the path app\code\PHPCuong\ShippingExpress\etc 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 app\code\PHPCuong\ShippingExpress\etc\adminhtml - Create the new file config.xml in the path app\code\PHPCuong\ShippingExpress\etc This file helps us to set the default value for the new shipping method. - Create the new file Express.php in the path app\code\PHPCuong\ShippingExpress\Model\Carrier 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 https://github.com/php-cuong/magento2-custom-shipping-method