Woo Distance Checkout - custom WooCommerce delivery plugin
Web ProgrammingDeveloped a custom WordPress plugin Woo Distance Checkout for a WooCommerce store. The task was to implement a full-fledged order checkout logic with two scenarios for receiving goods: delivery to the customer's address or pickup from the store.
For delivery, the plugin checks the address via Google Maps, determines the road distance from the store to the customer, and automatically calculates the cost based on a specified formula. A maximum delivery zone has also been implemented: if the address is outside the allowed radius, the user receives a clear message with the store's contact number.
Google Places Autocomplete is integrated into the checkout. When entering an address, the user sees suggestions, and after selecting the desired option, the data is automatically distributed among the street, city, state, postal code, and country fields.
For the security of the API integration, separate keys are used:
* frontend key for Google Places Autocomplete;
* server key for Google Geocoding API and Distance Matrix API.
For tax calculation, the Sales Tax Rates API is integrated via RapidAPI. The tax rate is determined by the ZIP code of the delivery address, and for pickup, it is based on the ZIP code of the store address. The `combined_rate` from the API response is used, which is the total tax rate. The result is cached in the WooCommerce session to avoid repeated API requests for the same ZIP code.
In Pickup mode, the billing address fields are automatically filled with the store's address and smoothly hidden. The customer's contact details remain accessible. The delivery cost for pickup is zero, and the tax is calculated based on the pickup point address.
Implemented functionality:
* choice between Delivery and Pickup;
* Google Places Autocomplete;
* server-side address validation via Google Geocoding API;
* calculation of road distance via Google Distance Matrix API;
* automatic delivery calculation by miles;
* base rate, price per mile, minimum cost, and rounding;
* maximum delivery zone;
* automatic filling of the store address for pickup;
* Sales Tax Rates API via RapidAPI;
* tax calculation by ZIP code;
* combined Sales Tax string displaying the percentage rate;
* caching of validation, distance, and tax results;
* fallback scenarios when the Tax API is unavailable;
* blocking checkout or manual order verification;
* saving calculations in order metadata;
* separate dashboard in WooCommerce Admin;
* notifications on the order confirmation page;
* debug mode for testing and diagnostics;
* support for WordPress i18n;
* compatibility with standard WooCommerce checkout.
The plugin is built on a modular architecture. Distance calculation, address validation, taxes, checkout controller, metadata storage, administrative part, and logging are separated into distinct classes. This simplifies maintenance, testing, and further expansion of functionality.
Result: the store received a stable and clear checkout that automatically determines delivery availability, calculates its cost and Sales Tax, supports pickup, and correctly handles external API failures. The solution was tested on real addresses and accepted by the client.
#WordPress #WooCommerce #PHP #JavaScript #AJAX #CustomPluginDevelopment #WooCommerceCheckout #GoogleMapsAPI #GooglePlacesAPI #GeocodingAPI #DistanceMatrixAPI #RapidAPI #SalesTaxRatesAPI #SalesTaxCalculation #ZIPCodeTaxCalculation #DistanceBasedShipping #DeliveryCalculation #AddressValidation #Pickup #APIIntegration #WordPressHooks #OrderMeta #Internationalization #Debugging #CheckoutUX
For delivery, the plugin checks the address via Google Maps, determines the road distance from the store to the customer, and automatically calculates the cost based on a specified formula. A maximum delivery zone has also been implemented: if the address is outside the allowed radius, the user receives a clear message with the store's contact number.
Google Places Autocomplete is integrated into the checkout. When entering an address, the user sees suggestions, and after selecting the desired option, the data is automatically distributed among the street, city, state, postal code, and country fields.
For the security of the API integration, separate keys are used:
* frontend key for Google Places Autocomplete;
* server key for Google Geocoding API and Distance Matrix API.
For tax calculation, the Sales Tax Rates API is integrated via RapidAPI. The tax rate is determined by the ZIP code of the delivery address, and for pickup, it is based on the ZIP code of the store address. The `combined_rate` from the API response is used, which is the total tax rate. The result is cached in the WooCommerce session to avoid repeated API requests for the same ZIP code.
In Pickup mode, the billing address fields are automatically filled with the store's address and smoothly hidden. The customer's contact details remain accessible. The delivery cost for pickup is zero, and the tax is calculated based on the pickup point address.
Implemented functionality:
* choice between Delivery and Pickup;
* Google Places Autocomplete;
* server-side address validation via Google Geocoding API;
* calculation of road distance via Google Distance Matrix API;
* automatic delivery calculation by miles;
* base rate, price per mile, minimum cost, and rounding;
* maximum delivery zone;
* automatic filling of the store address for pickup;
* Sales Tax Rates API via RapidAPI;
* tax calculation by ZIP code;
* combined Sales Tax string displaying the percentage rate;
* caching of validation, distance, and tax results;
* fallback scenarios when the Tax API is unavailable;
* blocking checkout or manual order verification;
* saving calculations in order metadata;
* separate dashboard in WooCommerce Admin;
* notifications on the order confirmation page;
* debug mode for testing and diagnostics;
* support for WordPress i18n;
* compatibility with standard WooCommerce checkout.
The plugin is built on a modular architecture. Distance calculation, address validation, taxes, checkout controller, metadata storage, administrative part, and logging are separated into distinct classes. This simplifies maintenance, testing, and further expansion of functionality.
Result: the store received a stable and clear checkout that automatically determines delivery availability, calculates its cost and Sales Tax, supports pickup, and correctly handles external API failures. The solution was tested on real addresses and accepted by the client.
#WordPress #WooCommerce #PHP #JavaScript #AJAX #CustomPluginDevelopment #WooCommerceCheckout #GoogleMapsAPI #GooglePlacesAPI #GeocodingAPI #DistanceMatrixAPI #RapidAPI #SalesTaxRatesAPI #SalesTaxCalculation #ZIPCodeTaxCalculation #DistanceBasedShipping #DeliveryCalculation #AddressValidation #Pickup #APIIntegration #WordPressHooks #OrderMeta #Internationalization #Debugging #CheckoutUX