# Saudi Address Pro — WooCommerce Plugin

**Version:** 1.1.1
**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

### Optional delivery instructions (local implementation; release pending)

Enable **Saudi Address Pro → Delivery instructions** to offer an optional Arabic/English
250-character field on classic and block checkout. Off by default; leave off if another
field already collects delivery instructions. Existing WooCommerce order notes are not changed.
Instructions are unverified customer requests and must not contain passwords, gate codes or
sensitive information. They are saved as `_saudadpr_delivery_instructions` and displayed on the
admin order page. The optional native label action maps this value automatically;
custom integrations can also map it to the renderer's `deliveryInstructions` input.
This does not automatically print to a physical printer or send notes to a carrier.

## Saudi Address Pro Delivery Label

After updating the plugin, enable this off-by-default feature in Saudi Address Pro
settings. Open a Saudi order under WooCommerce → Orders, then choose **Print Saudi
Address Pro Delivery Label** below the shipping address. Saved recipient, Short
Address and optional instructions are included automatically. The server rechecks
the address with SPL using your normal lookup allowance. Branded and monochrome
output can be printed or saved as PDF through the browser.

Optionally include an order link in merchant new-order emails. The link requires
staff login and order-edit permission; it is never added to customer emails and
does not attach a PDF. No lookup occurs while preparing the email. Both legacy
and HPOS order storage use the same WooCommerce order API. No additional plugin
or developer integration is required. This is an address companion, not an
official courier shipping label. Source implementation is not WordPress.org
publication or real completed-order verification.

Normal checkout waits for an outstanding save; failed saves show a retry action.
Notes clear when the observed shipping destination leaves Saudi Arabia. Custom checkout/payment
flows require separate compatibility checks. No real WordPress checkout/order verification or
WordPress.org release is implied by local tests.

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
