How to Customize Magento 2 Shipping Methods

Jonathan Anderson
E-Commerce Manager

This is a weekly series detailing common issues that can occur during Magento 2 custom development. Check back next week for more solutions.

This week we’ll start off with building custom shipping methods to match a client’s specific business needs. We developed a custom site for Milk Jar Cookies (MJC), using Magento 2 as a backend. Magento 2’s out of box support for custom shipping options leaves a bit to be desired, however, we enacted a number of workarounds.MJC HomepageMilk Jar Cookies, a local boutique cookie shop, came to us with the issue of ordering cookies online with three different types of delivery, as well as a new monthly subscription process they wanted to implement. They offered their customers the option of:

1. In-Store Pick-Up

2. Local Courier Delivery

3. Traditional Shipping via UPS

With these three requirements defined, we ran into a number of roadblocks. Each requirement had to follow its own set of rules in order for the system to function as MJC wished.

To compound matters, MJC had a number of products that were only eligible for specific types of delivery, and at specific times! For example, a carton of milk is only able to be picked up, or courier delivered, but not shipped via UPS, as it would spoil in the process. Additionally, a monthly subscription of cookies, could only be shipped to an address, and not picked up in store. Lastly, there were time requirements around when an order could be placed, and when it could be picked up or delivered by courier.

For In-Store Pick-Up, we were simply able to alter the default Magento 2 option of flat-rate shipping to 0, and change its name to Pick-Up. We then extended the BSS Commerce Order Delivery Date Extension and by modifying the shipping component using Magento 2’s knockout.js framework to implement MJC’s specific timing rules.

Magento 2 Backend

For Local Courier Delivery, MJC could only allow a 3-mile radius from their flagship store, as well as specific delivery periods throughout the day. We chose to implement Table-Rates, which Magento 2 offers natively to configure the fees based upon delivery zip code. This allowed us to enter the approved zip codes surrounding MJC, which were eligible for courier delivery. Again, we had to modify the shipping component via knockout.js in order to implement the specific timing rules controlling available delivery times based upon order time.

MJC-Shipping

Finally, the easy one, for Traditional Shipping via UPS, the only modification that we needed to make was to alter the shipping component to read the cart to disallow traditional shipping if there was any milk in a customer’s cart. Phew!

MJC-Error

In summary, we’ve now discovered that complex and custom shipping rules in Magento 2 are possible to implement. Our understanding of knockout.js and the shipping component have really developed through this experience.

We hope this article has provided you a bit of insight and guidance on how to modify Magento 2 to meet your needs, and directed you away from common pitfalls.

- Jonathan AndersonE-Commerce Manager | 

Filed under: <E-commerce>