Longitude and Latitude Assigner to Orders
Assigns and manages longitude and latitude data for WooCommerce orders.
by Pedro Consuegra · github.com/peterconsuegra/longitude-and-latitude-assigner · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/peterconsuegra/longitude-and-latitude-assigner/archive/refs/heads/main.zipWordPress plugin that geocodes WooCommerce shipping addresses with the Google
Geocoding API and stores the coordinates on the order, so
Save a Playa's deliveries can be mapped and
analysed by location (the coordinates are exported by woo-gender-analytics
as order_lat / order_lng).
- Author: Pedro Consuegra — https://pedroconsuegra.com
- Version: 1.8.0
- Requires: WordPress, WooCommerce, a Google Maps Platform key with the Geocoding API enabled
- License: GPL-2.0
How it works
- Automatically — when an order reaches
processing(woocommerce_order_status_processing, withwoocommerce_order_status_changedas a fallback), the order is geocoded once. A short transient lock stops duplicate calls when both hooks fire, and orders that already have coordinates are skipped. - Manually — from Lat Long → Orders Shipping List, one order at a
time (Get lat/long button) or in bulk for the selected rows
(AJAX
lla_get_coords, capabilitymanage_woocommerce+ nonce).
The address sent to Google is the shipping address, falling back to billing
when the shipping address is incomplete. Colombian cities are normalised
before the call: the (DEPT) suffix used by the checkout city list is
stripped, BOGOTA / MEDELLIN get their accents back, and the state code is
expanded to its name.
Order meta written
| Meta | Value |
|---|---|
order_lat, order_lng |
coordinates from the first Google result |
order_geocode_status |
Google status (OK, ZERO_RESULTS, REQUEST_DENIED…) or WP_ERROR |
order_geocode_error |
Google's error_message / the WP error, when the call failed |
order_geocode_formatted_address, order_geocode_place_id |
Google's normalised address and place ID |
Admin screens
A top-level Lat Long menu (capability manage_woocommerce) with two
screens:
| Screen | Slug | What it does |
|---|---|---|
| Orders Shipping List | wc-orders-shipping-list |
Processing + completed orders with client, shipping state/city/address and the stored lat/lng. Filter by city (Bogotá, Medellín, Cali, Barranquilla, Bucaramanga, Bello, Pasto, Pereira, Villavicencio, Cartagena, or All other cities), page size 10–1000, per-row and bulk geocoding. |
| Lat/Lng Settings | lla-latlng-settings |
Saves the Google API key (lla_google_maps_api_key option) and runs a test geocode of "Bogotá, Colombia" to confirm the key works. |
City filtering matches the several spellings a city arrives with (BOGOTA (C/MARCA), Bogotá, BOGOTA…) through lla_city_like_variants().
Requirements
- Works with classic order storage and with HPOS (
lla_is_hpos_enabled()switches the list queries towc_orders; the meta is written withupdate_post_meta, so with HPOS enabled keep compatibility mode / sync on). - With
WP_DEBUGon, every geocode request (original and prepared address, endpoint, parameters) is logged todebug.log.
Changelog
- 1.8.0 — Own top-level Lat Long admin menu (Orders Shipping List, Lat/Lng Settings) instead of two entries under WooCommerce; page URLs unchanged.
- 1.7.1 — previous release.
Billing note
Every geocode is a paid Google API call. The automatic hook makes exactly one per new processing order; the bulk button makes one per selected order that has no coordinates yet.