Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/dezefy/woocommerce-distance-based-shipping-restrictions/archive/refs/heads/main.zipDistance-Based Shipping Restriction
The Distance-Based Shipping Restriction plugin is a WooCommerce plugin that allows you to block orders if the shipping address is too far away from your store location. The plugin uses the Google Maps API to calculate the distance between the store location and the customer's shipping address. If the distance is more than a specified maximum distance, the plugin will block the order and display a custom error message to the customer.
Features
The Distance-Based Shipping Restriction plugin has the following features:
- Distance-based shipping restriction: You can specify a maximum distance from your store location, beyond which orders will be blocked. The maximum distance can be set in kilometers or miles, and the plugin will automatically convert it to meters for the Google Maps API.
- Custom error message: You can customize the error message that is displayed to the customer if their shipping address is too far away from your store location. The error message can include a placeholder for the actual distance, which the plugin will automatically replace with the calculated distance.
- Google Maps API integration: The plugin integrates with the Google Maps API to calculate the distance between your store location and the customer's shipping address. To use the plugin, you will need to obtain a Google Maps API key and enter it in the plugin settings.
How it works
To use the Distance-Based Shipping Restriction plugin, you will need to follow these steps:
- Install and activate the plugin in your WooCommerce store.
- Go to the plugin settings page and enter your Google Maps API key. You can also set the maximum distance and the custom error message in the settings.
- When a customer places an order, the plugin will use the Google Maps API to calculate the distance between your store location and the customer's shipping address.
- If the distance is more than the specified maximum distance, the plugin will block the order and display the custom error message to the customer.
- If the distance is within the maximum distance, the order will proceed as usual.
Overall, the Distance-Based Shipping Restriction plugin is a simple yet powerful tool for managing shipping restrictions based on distance. With this plugin, you can ensure that you only accept orders from customers who are within a certain distance from your store location, which can help you save time and money on shipping costs.


How to get a Google Maps API key
To get a Google Maps API key, follow these steps:
- Go to the Google Cloud Console at https://console.cloud.google.com/.
- If you don't already have a Google Cloud account, you will need to create one. Click the "Select a project" dropdown menu at the top of the screen and click "New Project". Follow the prompts to create a new project.
- Once you have created a project or selected an existing one, click on the navigation menu (☰) in the top-left corner of the screen and select "APIs & Services" > "Dashboard".
- Click the "+ ENABLE APIS AND SERVICES" button at the top of the screen.
- Search for "Maps JavaScript API" and click on it in the search results.
- Click the "ENABLE" button to enable the Maps JavaScript API for your project.
- Click the "Create Credentials" button at the top of the screen.
- Select "API key" from the dropdown menu.
- If prompted, enter a name for your API key.
- Click the "Create" button.
- Your API key will now be displayed on the screen. Copy it and save it somewhere safe.
That's it! You now have a Google Maps API key that you can use to integrate the Distance-Based Shipping Restriction plugin with the Google Maps API. Remember to keep your API key secure and never share it with anyone.