Skip to content

Feature: Add WooCommerce HPOS compatibility for orders - #4038

Open
felipeelia wants to merge 83 commits into
developfrom
feature/wc-hpos-issue-3476
Open

felipeelia wants to merge 83 commits into
developfrom
feature/wc-hpos-issue-3476

Conversation

@felipeelia

@felipeelia felipeelia commented Dec 10, 2024 •

Copy link
Copy Markdown
Member

Description of the Change

Adds ElasticPress support for WooCommerce High-performance order storage (HPOS) on the admin Orders list.
When HPOS is enabled and WooCommerce is 9.9.0 or greater, ElasticPress now:

  • Indexes HPOS orders into the post indexable
  • Intercepts HPOS order list queries via woocommerce_hpos_pre_query
  • Translates HPOS query args into Elasticsearch-compatible queries (OrdersHPOS / OrdersHPOSQuery)
  • Continues to support Orders Autosuggest on ElasticPress.io when HPOS is compatible
    Compatibility details:
  • HPOS integration requires WooCommerce 9.9.0+ (ep_woocommerce_hpos_min_version)
  • On WooCommerce below 9.9.0 with HPOS enabled, EP does not integrate with the orders list and shows an admin notice
  • Orders stored as posts remain supported on older WooCommerce versions
  • Autosuggest is only marked HPOS-incompatible when HPOS is actually enabled on an unsupported WooCommerce version

Closes #3476

How to test the Change

  1. On WooCommerce 9.9.0+, enable HPOS (wp wc hpos enable), enable WooCommerce + Protected Content, and sync.
  2. Visit WooCommerce → Orders (admin.php?page=wc-orders) and confirm list search/filters go through Elasticsearch.
  3. Create/update an order and confirm it is indexed/updated.
  4. With ElasticPress.io available, enable Orders Autosuggest and confirm suggestions appear on the HPOS orders screen.
  5. On WooCommerce below 9.8.0 with HPOS enabled, confirm:
    • EP does not integrate with the HPOS orders list
    • The HPOS incompatibility notice appears on the orders screen
    • Autosuggest shows the HPOS version help message
  6. Disable HPOS (orders as posts) on WooCommerce below 9.8.0 and confirm legacy order search/autosuggest still work.

Changelog Entry

Added - Compatibility with WooCommerce High-performance order storage (HPOS) for the admin Orders list on WooCommerce 9.9.0+.

Credits

Props @felipeelia @burhandodhy

Checklist:

@felipeelia felipeelia added this to the 5.2.0 milestone Dec 10, 2024
@felipeelia felipeelia modified the milestones: 5.2.0, 5.3.0 Apr 10, 2025
@felipeelia felipeelia modified the milestones: 5.3.0, 5.4.0 Sep 18, 2025
@burhandodhy
burhandodhy force-pushed the feature/wc-hpos-issue-3476 branch from ce29915 to 9d558a0 Compare February 12, 2026 08:12
@burhandodhy
burhandodhy force-pushed the feature/wc-hpos-issue-3476 branch from 2317e7e to da0040e Compare February 19, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

HPOS-only full sync, metadata privacy, filter interoperability, pagination, and date-filter correctness have unresolved defects.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

includes/classes/Feature/WooCommerce/OrdersHPOS.php:320

  • Preserve an override supplied by an earlier woocommerce_hpos_pre_query callback. This filter's first argument is the accumulated pre-query result; returning null here discards another integration's valid result and causes either ElasticPress or WooCommerce SQL to run instead.
	public function maybe_intercept_wc_orders_query( $order_data, OrdersTableQuery $query ) {
		if ( ! $this->should_integrate_with_query( $query->get_query_args(), $query ) ) {
			return null;
		}

includes/classes/Feature/WooCommerce/OrdersHPOSQuery.php:124

  • When callers provide both offset and page, WooCommerce gives the explicit offset precedence, but ElasticPress's post query recalculates from from paged and overrides this offset. Resetting paged when an offset is present preserves HPOS query semantics.
		$offset = $this->hpos_query->get( 'offset' );
		if ( ! empty( $offset ) ) {
			$args['offset'] = absint( $offset );

includes/classes/Feature/WooCommerce/OrdersHPOSQuery.php:732

  • WooCommerce's date query contract accepts Unix timestamps, but an integer date_created/date_modified value is rejected here, so build_date_query() silently drops the filter. Permit numeric scalars and cast them before normalization.
	protected function parse_date_shorthand( $value ): array {
		if ( ! is_string( $value ) || empty( $value ) ) {
			return [];
		}
  • Files reviewed: 20/21 changed files
  • Comments generated: 5
  • Review effort level: Balanced

Treat GMT date shorthand and exclusive date_query after values as
GMT so Elasticsearch results match WooCommerce.
Treat an empty status as every post status, keep customer 0 as a
guest filter, and count all orders still pending sync.
Read dates, parent, and notes from the edit context and store boolean
meta the way WooCommerce does. Keep existing query results when
Elasticsearch is skipped, and build the meta query in one pass.
Translate date_query and field_query in their own classes so
Elasticsearch follows WooCommerce comparisons, and fall back when a
query cannot be translated. Update the WooCommerce test dependency
to 11.2.1.

Copilot AI left a comment

Copy link
Copy Markdown

Give a set offset precedence over the page when a valid limit is set,
and remove deleted refunds on woocommerce_delete_order_refund.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compatibility with WooCommerce HPOS

3 participants