Address autocomplete and checks for WooCommerce

WooCommerce can suggest addresses at checkout, but the providers behind it send every keystroke to an outside service and bill for it. The GridPin plugin is a provider of WooCommerce's own autocomplete that asks a geocoder beside the shop.

New Take addresses in Self-hosted apps Retail, e-commerce

What you have

A WooCommerce shop (9.9 or later) on a server where you can run a program, the country file, and the plugin folder integrations/woocommerce/gridpin-address.

Steps

1. Start the server and leave it running:

terminalCLI
$ gridpin serve germany.bin --port 8080

2. Put the plugin in wp-content/plugins, activate GridPin Address for WooCommerce, turn on Settings → General → Enable address autocomplete.

3. At checkout the plugin asks the server for suggestions as the customer types:

terminalCLI
$ curl -s 'http://127.0.0.1:8080/v1/suggest?q=Albrechtstra%C3%9Fe%205%2C%20Ber&k=3'
{"suggestions":[{"commune":"Bernburg (Saale), Stadt","label":"Albrechtstraße 5, Bernburg (Saale), Stadt","lat":51.7878554,"lon":11.7398949,"precision":"house","street":"Albrechtstraße"}]}

4. After the order it checks the delivery address:

terminalCLI
$ curl -s 'http://127.0.0.1:8080/v1/exists?q=Albrechtstra%C3%9Fe%20999%2C%2006406%20Bernburg%20(Saale)'
{"exists":"no","reason":"number_not_on_street"}

What you get

The customer picks an address and the street, number and town are filled. An order to an address the file does not know gets a private note to check it before shipping; the order is never blocked.

Why it works

The plugin registers as a WooCommerce address provider; its two shop routes ask /v1/suggest and /v1/exists of your server. No address leaves your server.

Limits

  • Shared hosting that only runs PHP is not enough: the server is a program.
  • Suggestions only when the checkout country is the country of the file.
  • Not in the WordPress directory yet; licence GPL-2.0-or-later (the plugin only).

The function: WooCommerce. Related: self-hosted address autocomplete, CEP lookup for Brazilian shops.