Magento 2 Distance Based Shipping

Magento 2 Distance Based Shipping allows the admin to create a custom shipping method where the shipping rate is calculated based on the unit distance between the store's warehouse and the customer's delivery location.

 

Table of Content

  1. Extension Installation Guide
  2. Configuration
  3. Warehouse Manager
  4. Distance Based Shipping in Frontend
  5. Distance Based Shipping in Backend

 

  1. Extension Installation
    • For Magento Marketplace Customers
      • Create a folder structure in Magento root as app/code/Meetanshi/DistanceBasedShipping
      • Download and extract the zip folder and upload our extension files to the app/code/Meetanshi/DistanceBasedShipping via FTP.
      • Login to your SSH and run below commands step by step:
        • php bin/magento setup:upgrade
        • For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
        • For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
        • php bin/magento cache:flush

 

    • For Meetanshi Customers
      • Extract the zip folder and upload our extension to the root of your Magento 2 directory via FTP.
      • Login to your SSH and run below commands step by step:
        • php bin/magento setup:upgrade
        • For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
        • For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
        • php bin/magento cache:flush

 

  1. Configuration
    For configuring the extension, login to Magento 2, move to Sales à Shipping Methods à Distance Based Shipping – Meetanshi where you can find various settings to enable the extension.
  • Enabled: Set “YES” to enable Distance Based Shipping extension.
  • Title: Enter title for the shipping method.
  • Method Name: Enter the method name for the shipping method.
  • Displayed Error Message: Enter the error message to show for shipping unavailability.
  • 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.

 

    • Go to APIs & Services > Library.

 

 

    • Click “View All” under Maps category and enable 4 APIs: Distance Matrix APIs, Geolocation API, Maps JavaScript API, Places API.

 

    • Click the menu button and select APIs & Services > Credentials. On the Credentials page, click Create credentials > API key Or edit an API if already created. You can copy the Google Map API Key from here.

 

  • Distance Unit: Select one of the distance units to calculate distance.
    • Kilometres
    • Meters
    • Miles Yards
  • Shipping Cost: Set shipping cost based on the calculated distance.
    • From (Distance Unit): Set minimum distance.
    • To (Distance Unit): Set maximum distance.
    • Cost: Set shipping cost.
    • Type: Select one the shipping cost calculation types.
      • Fixed: Fixed amount as in Cost.
      • Per Unit: Distance Calculated x Amount in the Cost.
  • Minimum Order Amount: Set minimum order amount to allow using this shipping method.
  • Maximum Order Amount: Set maximum order amount to allow using this shipping method.
  • Maximum Distance for Shipping: Enter the maximum distance to allow shipment.
  • Ship to applicable countries: Select all allowed countries to enable Distance Based Shipping for.
  • Ship to specific countries: Select countries to enable Distance Based Shipping for.
  • Show Method if Not Applicable: Select YES to show the shipping method even if it’s not applicable.
  • Sort Order: Add sort order of the shipping method.

 

 

  1. Warehouse Manager
    The extension facilitates to manage warehouses through a separate backend grid. Go to Distance Based Shipping > Warehouse Manager. All the already created and saved warehouses seen enlisted here.

 

  • Click “Add New Warehouse” to add a new warehouse.
    • Status: Enable warehouse from here.
    • Street: Enter street address for the warehouse.
    • City: Enter name of the city in which the warehouse is located.
    • Country: Select country in which the warehouse is located.
    • State: Select state in which the warehouse is located.
    • Zip Code: Enter zip code of the location of the warehouse.

 

  1. Distance Based Shipping in Frontend
    Once you have set distance-based shipping costs, you can see distance-based shipping rates extension enabled in the frontend. After adding products to cart, the customer selects the warehouse, adds the shipping destination and Google Maps API calculates the distance between these two and shows the shipping cost. Once it’s selected, the respective shipping rate will be applied on the order.

 

  • Distance Based Shipping on Checkout Page

 

 

  • Distance Based Shipping in “My Account” Section
    Once the order is placed using Distance Based Shipping method, under the “My Orders” tab, shipping details are seen.

 

 

  1. Distance Based Shipping in Backend
    Apart from the frontend, the Distance Based Shipping method details can also be seen from the backend under Sales à Orders. The below image shows the order view where Distance Based Shipping details are visible.