# Saudi Address Pro — WooCommerce Plugin

**Version:** 1.1.0
**Requires WordPress:** 6.0+
**Tested up to:** WordPress 7.0
**Requires WooCommerce:** 5.0+
**Tested up to WooCommerce:** 10.6
**Requires PHP:** 7.4+
**License:** GPL v2 or later

---

## What it does

Adds a Saudi National Address (SPL) autocomplete widget to your WooCommerce checkout. Customers type an 8-character short code (e.g. `RCTB4359`) and the plugin instantly auto-fills all address fields with the verified SPL address — no typos, no invalid addresses.

Built for the **TGA January 2026 mandate** requiring valid Saudi National Addresses on all parcel deliveries in Saudi Arabia.

---

## Compatibility

| Platform | Status |
|---|---|
| WordPress 7.0 | ✅ Tested & compatible |
| WordPress 6.x | ✅ Fully supported |
| WooCommerce 10.6 | ✅ Tested & compatible |
| WooCommerce Classic Checkout | ✅ Supported |
| WooCommerce Block Checkout | ✅ Supported |
| HPOS (High-Performance Order Storage) | ✅ Declared compatible |
| PHP 7.4 – 8.3 | ✅ Supported |

---

## Order emails and privacy

When a valid Saudi short address is saved with an order, it is included in the standard WooCommerce transactional order emails sent to the customer and store administrators. The email integration reads the plugin's order meta through WooCommerce CRUD, so it works with both legacy order storage and HPOS. It includes only a valid 8-character short code, not additional address data.

Checkout searches are proxied through WordPress so the merchant API key remains server-side. A Short Address is written to order metadata only after an authoritative SPL lookup verifies it in the current WooCommerce session; the verified selection is time-limited, bound to the active cart when available, and consumed after one order.

### Manual acceptance checks

This repository has no WooCommerce PHP test suite. Before release, verify the following in a WooCommerce test store:

1. Place a classic-checkout order with a valid short address and confirm the customer order email and new-order admin email each show `Saudi Short Address: RCTB4359`.
2. Repeat with block checkout and HPOS enabled; confirm both emails show the saved code.
3. Place an order without a short address, and an order whose stored `_saudadpr_short_address` meta is invalid; confirm no short-address line is included.
4. Switch WooCommerce emails between HTML and plain text; confirm the line is readable in each format and no full address is added by this integration.
5. In block checkout, select an address (including through **Find on map**) and immediately press Place order. Confirm checkout waits for the session save and the resulting order contains the selected short address.
6. Simulate a failed `saudadpr_save_session` request in block checkout. Confirm an actionable error is announced, Place order does not proceed, and the widget does not report the code as session-saved. Repeat the same selection and confirm only one in-flight save request is made.

---

## Installation

1. Download the plugin zip from [WordPress.org](https://wordpress.org/plugins/saudi-address-pro/) or this repository
2. In your WordPress admin go to **Plugins → Add New → Upload Plugin**
3. Upload the zip and click **Activate**
4. Go to **Saudi Address Pro** in the sidebar and enter your API key
5. Get a free API key at [saudiaddresspro.com](https://saudiaddresspro.com)

---

## Changelog

### 1.1.0 — September 2026
- Kept merchant API credentials out of checkout JavaScript by proxying customer searches through a nonce-protected WordPress endpoint.
- Added authoritative server-side Short Address verification before WooCommerce session/order persistence or SMSA prefill.
- Rendered API-provided checkout values as text and added one-time, cart-bound verification state to prevent injection, forgery, and cross-order reuse.
- Added the saved Saudi short address to WooCommerce customer and administrator transactional order emails using HPOS-compatible WooCommerce order meta access.
- Added an optional checkout map lookup modal. It embeds the Saudi Address Pro map without passing the merchant API key; only a verified 8-character short address returns through an origin- and per-open nonce-checked `postMessage` contract. The code is then saved through the existing classic hidden field and block-checkout session endpoint.
- The embed is intentionally limited to HTTPS merchant frames (plus localhost loopback for development). If a restrictive merchant Content Security Policy blocks `saudiaddresspro.com`, the merchant must allow it in `frame-src`.
- Block checkout now coordinates Place order with the observable short-address session save, including map selections. Failed saves are shown to the customer and do not allow a Store API order to proceed with an unsaved code.

### 1.0.5 — May 2026
- Declared compatibility with WordPress 7.0
- Updated tested-up-to for WooCommerce 9.9
- Added missing `Tested up to` header (removes WordPress.org "not tested" warning)
- Updated minimum WordPress requirement to 6.0

### 1.0.4
- Settings prefix migration for existing installations
- HPOS compatibility declaration

### 1.0.3
- Block checkout support
- Arabic RTL layout

### 1.0.0
- Initial release
