# Changelog

All notable changes to this plugin will be documented in this file.

---

## [1.3.1] - 2026-05-22

### Fixed
- Fixed HPOS (High-Performance Order Storage) compatibility: replaced all `get_post_meta()`, `update_post_meta()`, `delete_post_meta()`, and `delete_post_meta_by_key()` calls for order meta with the WooCommerce order object API (`get_meta()`, `update_meta_data()`, `delete_meta_data()`, `save()`).
- Fixed `fetch_orders()` in order fetcher to use `wc_get_orders()` instead of `get_posts()` with `post_type=shop_order`, ensuring HPOS compatibility.
- Fixed meta box registration to support both HPOS (`woocommerce_page_wc-orders`) and legacy (`shop_order`) order edit screens.
- Fixed `render_order_meta_box()` callback to handle both `WC_Order` (HPOS) and `WP_Post` (legacy) as the callback argument.
- Fixed `handle_order_update()` method signature to accept the 4th `$order` parameter passed by the `woocommerce_order_status_changed` hook.
- Fixed `rebuild_groups()` to clear order sync meta using HPOS-compatible order object methods instead of `delete_post_meta_by_key()`.
- Fixed `count()` called inside `for` loop conditions in `build_group_match_summary()` — extracted to a variable before the loop.
- Fixed all `$table_name` SQL interpolations in handler, orders table, admin, and order fetcher to use `esc_sql()` before interpolation.
- Fixed `$query` in `fetch_grouped_orders()` to always pass through `$wpdb->prepare()` rather than calling `get_results()` with a raw string.
- Fixed `$count_query` and `$list_query` in `prepare_items()` to suppress `PluginCheck.Security.DirectDB.UnescapedDBParameter` with explicit `phpcs:ignore`.
- Fixed `$group_query` in `ajax_regroup_group()` and `update_group_status()` to use `esc_sql()` on the table name.
- Fixed `table_has_required_columns()` in installer to use `esc_sql()` on the table name before interpolation.
- Fixed inconsistent indentation in `load_dependencies()` in the loader class.
- Fixed missing `/* translators: */` comment on `__('%s ago')` in `group-details-popup.php`.
- Fixed unescaped `wp_strip_all_tags()` output inside `printf()` in `group-details-popup.php` — wrapped with `esc_html()`.
- Fixed `get_post_meta()` call for order meta in `group-details-popup.php` template — replaced with HPOS-compatible `$order->get_meta()`.
- Fixed `$status_label` output in `admin-page.php` — wrapped with `esc_html()` before passing to `printf()`.
- Fixed `NonPrefixedVariableFound` PHPCS warnings across all template files by adding inline `phpcs:ignore` annotations and `@var` docblocks.
- Fixed `WC_Order_Item_Product` type guard missing in `build_group_summary_response()` — added `instanceof` check before calling `get_product_id()`.

### Security
- Escaped all table name interpolations in SQL queries with `esc_sql()` across handler, orders table, admin, and order fetcher classes.
- Ensured all dynamic SQL queries pass through `$wpdb->prepare()` with no raw string passed directly to `get_results()` or `get_var()`.

### Compatibility
- Confirmed tested up to WordPress 7.0.
- Updated readme short description to comply with the 150-character limit.

---

## [1.3.0] - 2026-04-06

### Added
- Added configurable time-window grouping so only recent repeat orders are auto-grouped together.
- Added confidence score, confidence level, match-reason metadata, and suggested parent order tracking for each group.
- Added exclusion controls for statuses, payment methods, COD, virtual-only orders, and already linked orders.
- Added richer group review modal workflows including recommendation banner, shipment summary, export actions, timeline, regroup, unlink, and exclusion tools.
- Added new REST API read routes for group summaries, detection settings, and exclusion settings.

### Changed
- Expanded the Group Orders admin table with confidence, suggested parent, status workflow controls, and stronger review actions.
- Improved audit logging to capture confidence calculations, exclusion decisions, regroup activity, and manual workflow state changes.
- Updated plugin documentation and REST API docs to reflect the new v1.3.0 workflow and endpoints.

### Fixed
- Kept linked, review, and excluded states consistent across popup actions, table actions, AJAX handlers, and REST unlink flows.
- Fixed popup behavior so linked groups stay locked correctly and unlink/regroup actions behave in-context.
- Restored `/orders` REST filtering support for `group_id` and `linked_status`, and added support for `group_status` and `confidence_level`.

---

## [1.2.3] - 2026-03-03

### Added
- Added a dedicated **Rebuild Multiple Orders** submenu page for focused rebuild workflows.

### Changed
- Simplified the main **Multiple Orders** screen by moving rebuild operations to the new submenu.
- Improved admin UI/UX with clearer section hierarchy, better filter/table presentation, and a modernized rebuild layout.
- Refined user-facing terminology across menus, headings, table labels, notices, and popup content for consistency.

### Improved
- Streamlined troubleshooting flow by separating list management and rebuild operations.

---

## [1.2.2] - 2025-12-09

### Changed
- Performed full plugin integrity and compatibility checks across current WordPress and WooCommerce releases.
- Verified settings migration, metadata consistency, and renamed meta keys after the v1.2.x updates.

### Fixed
- Minor bug fixes and cleanups:
  - Resolved a race condition in AJAX linking that could leave stale meta on some orders.
  - Fixed an edge case in the "More" tab where recommendations could duplicate.
  - Ensured transients and caches are invalidated after settings changes.

### Tested
- Confirmed REST API and AJAX endpoints (including authentication) return expected responses.
- Validated multisite order fetching and metadata persistence for linked orders.
- Verified admin upgrade routine and notices run without errors.

---

## [1.2.1] - 2025-08-27

### Added
- Introduced a new **"More"** tab under the plugin settings page for plugin discovery and upsell.
- Added premium plugin showcase to help store owners find useful tools:
  - **Sequel247 Logistics Shipping** – Seamless Sequel API integration for shipping automation.
  - **Shipment Tracking** *(Coming Soon)* – Add, manage, and display tracking info on WooCommerce orders.
  - **Post/Page Import** *(Coming Soon)* – Import/export content between WordPress sites with preserved metadata.
  - **Activity Monitor Log** *(Coming Soon)* – Track and log key admin actions in the WP dashboard.

---

## [1.2.0] - 2025-08-22

### Changed
- **Renamed plugin**: Updated plugin name to **MultiOrder Sync** across all files, settings, and documentation.
- **Terminology updates**:
  - Replaced all references to **"Primary Order"** with **"Parent Order"**.
  - Replaced all references to **"Secondary Order(s)"** with **"Linked Order(s)"**.
  - Updated meta keys, labels, API responses, and internal methods for consistency.
- Updated admin UI, REST API, and settings pages to reflect the new terminology:
  - Admin meta boxes and linked order displays use updated wording.

## [1.1.0] - 2025-08-18

### Changed
- Improved the metadata structure used to store linked orders:
  - Now, **all linked orders** (parent and linked) consistently store a `multipleorders` meta entry.
- Updated the following methods to support full metadata persistence:
  - `ajax_link_orders()` now updates meta for **all orders** in the group.
  - `ajax_unlink_orders()` now properly removes metadata from all related orders.
  - `ajax_get_linked_order_details()` now outputs accurate linked order data.
- Improved the admin **Linked Orders** meta box with a clearer UI and accurate link details.
- Refactored the plugin settings page (`render_settings_page()`):
  - Now uses server-rendered tabs based on the `?tab=` URL parameter.
  - Only the active tab’s template is loaded, improving performance and clarity.
- Removed dependency on frontend JavaScript for tab switching.
- Updated admin settings templates:
  - Wrapped each tab’s content in individual PHP templates.
  - Templates are now loaded conditionally based on the selected tab.

### Deprecated
- Legacy partial `multipleorders` meta structure used prior to v1.0.1:
  - Was only set for the parent order (or only for secondaries).
  - **Fallback retained temporarily for backward compatibility.**
  - **Deprecated:** This fallback will be removed in a future major release (e.g., `v2.0.0`). Please update any custom code depending on the old structure.

### Fixed
- Fixed inconsistencies in how linked orders were displayed in the admin UI.
- Fixed issue where some linked orders were not saving metadata correctly.

---

## [1.0.0] - 2025-08-13

### Added
- Initial release of the MultiOrder Sync plugin.
- Ability to group WooCommerce orders based on customizable criteria.
- Link grouped orders into primary/secondary relationships.
- Admin UI for managing grouped orders.
- Settings panel for:
  - Order criteria.
  - Email templates.
  - Admin emails and CC.
  - API key.
- REST API:
  - Fetch grouped orders across the network:  
    `GET /wp-json/emw-mom/v1/orders`
  - Get multiple order group by order ID:  
    `GET /wp-json/emw-mom/v1/multiple-order-group/{order_id}`
- Multisite support: Fetch orders across all network sites.
- API authentication via custom API key header (`X-EMW-MOM-API-Key`).
- Toggle REST API docs in plugin settings.

### Fixed
- None — initial stable release.

### Security
- REST API secured via API key and admin toggle.

---
