User Guide of Magento 2 Distance Based Shipping Extension
General Configurations
At the backend, go to FME EXTENSIONS > Configurations. Here you can find the extension configurations.
- Enabled: Select ‘Yes’ to Enable or ‘No’ to Disable the module.
- Title: Give a custom title to the new shipping method. This will be displayed on frontend in the list of shipping methods.
- Google Map API key: Enter the Google map API key to auto calculate distance from the warehouse to the shipping destination for the distance-based shipping amount calculation. See the image below to know how to create the Google Map API Key.
- Admin Location: Enter your warehouse location.
-
Admin Latitude: This field is loaded automatically from Admin location using Geocoding API.
-
Admin Longitude: This field is loaded automatically from Admin location using Geocoding API.
-
Distance Unit: Select one of the following distance units to calculate distance
- Kilometer and feet
- Mile and meter
-
Shipping Cost: Select one of the following shipment methods to suggest cost.
- By Air
- By Road
-
Displayed Error Message: Enter an error message to display if this shipping method is not available for the country/region the user specified.
-
Show Method if Not Applicable: Select ‘Yes’ to show the distance based shipping method even if it’s not applicable.
-
Sort Order: Set sort order for this new shipping method.
Ho to Add Shipping Rules?
To make the extension work, you need to add rule(s). To do so, navigate to FME EXTENSIONS from the left sidebar and click Manage Shipping Rules. Now click Create New Rule to see the following options.
- Enable Shipping Rule: Toggle the button to Enable/Disable the rule.
- Rule Title: Give a title to the rule. This will display on frontend
- Rule Priority: Set priority for the rule. This helps if you have created multiple rules and want them to be executed in order. Lower the number, higher the priority.
- From & To: Set a duration for the rule by specifying the starting and ending date. The rule will only work within this time period.
- Store View: Select Store view(s) you want the rule to apply to.
Define Distance & Shipping Cost
Under Shipping Distance, you can see the following options.
- Cost Shipping: Select whether you want to charge shipping per item or for the whole Cart.
- Cost Distance: Select whether you want to charge a fixed shipping cost or per unit
- Distance From: Set minimum distance
- Distance To: Set maximum distance
- Cost: Set shipping cost
The Distance From and Distance To fields define the distance range and the Shipping Cost field defines the shipping cost for that range. In the example below, the shipping cost is $20 if the shipping distance is between 1 and 100 kilometers.
Select Customer & Customer Groups
Under the Select Customer Group/Customers section, you will find the following options. This section allows you to apply the rule to specific customers or customer groups i.e. the rule will only work for customers/customer groups you select.
-
Apply Rule Based On: Select one of the following options.
- Customer Groups
- Customers
-
Customer Groups: Select the customer group(s) you want to apply the rule to.
-
Under Select Customers, click Reset Filter and select the customer(s) you want to apply the rule to.
Conditions
The conditions section allows you to set conditions that will trigger the rule. You can use different shipping attributes i.e. shipping region, shipping postcode, shipping country etc. to set conditions. In this example, we will use Pakistan as the shipping country. This means we want to charge customers a shipping fee based on their distance in Pakistan from our warehouse location which is also in Pakistan. When this condition is met i.e. when a customer specifies Pakistan as her/his shipping destination, the rule will apply and the distance based shipping charges will display. You can target as many countries as you want.
If no condition is set, the rule will apply for all countries.
Refresh Cache
Refresh the Cache: System > Cache Management > Select All from Mass Actions > Click Refresh Cache.
Frontend
Once you have done all the configurations, you can see distance-based shipping rates extension enabled on the frontend. After adding products to cart and providing the shipping destination, Google Maps API calculates the distance between your admin location and the customer’s shipping location and shows the shipping cost. Once this shipping method is selected, the respective shipping rate will be applied on the order.