Magento 2 basic installation have three ‘offline’ shipping methods included: free shipping, flat rate and table rates.
They are called ‘offline’ because all shipping rates will be calculated using offline resources, basically only ‘table rates’ use advanced math and calculate fee according to provided CSV file.
Magento 2 also comes with four more shipping methods, dimensional weight methods (DHL, FedEx, UPS, USPS), that use external data to calculate how much customers have to pay for shipping.
Most popular ‘offline’ shipping method among customers is ‘free shipping’, everybody loves free shipping, they will pay just for products and there is no extra fee – great right 🙂
Now comes tricky part, free shipping has only one condition which is
One of our customers that have store based on Magento 2 platform noticed that among all stuff that they sell there are products that are heavy or bulky to be sent via regular shipping, however price of those products was high enough to enable free shipping. So his request was quite simple, to limit free shipping option to 120 lbs. of total cart weight, if items in cart go above that value ‘free shipping’ shouldn’t be available.
So we made small module that extend Magento ‘free shipping’ module by adding more field in Shipping Methods > Free Shipping tab, where admin can enter maximal weight for free shipping.
Here is the screen shot of admin section after we deployed our mini module:
Module simply extend condition that is located in Carrier file (notice that we added Rewrite folder to remeber that module overwrites core module):
app\code\Smdesign\FreeShipping\Model\Rewrite\Carrier\Freeshipping.php
so we now have too conditions that need to be fulfilled: Minimum Order Amount and
Instead copying parts of code and explaining every line I decided to provide module as package (please backup everything before deploy it) and I am quite sure that you will manage to grasp code in it.
Unpack archive into your Magento 2 installation root folder, navigate to /bin folder or use path in command line (as you like) and run commands in console:
magento module:enable Smdesign_FreeShipping
magento setup:upgrade
Please don’t hesitate to post comments I appreciate your feedback, any idea, improvement or reported bug/issue are more than welcome.
I am new to Magento 2 but eager to learn it and hope that will be able to post about it often.
Cheers 🙂