phpwoocommercehook-woocommerceordershighperformance

Filtering orders list in WooCommerce with HPOS


I'm in the process of converting an open source plugin to be HPOS-compatible. One of its features is additional filters on the orders list in admin (inline with the order statuses), eg: example

I can't seem to actually execute the modification of the query. Previously, I was hooking into pre_get_posts which obviously is no longer relevant when WP_Post is no longer being used.

Then the same for a filter field, for which I was hooking into restrict_manage_posts. found the equivalent hook: woocommerce_order_list_table_restrict_manage_orders

Anyone have an idea which hook to use?


Solution

  • As WC_Order_Query is used to query orders for HPOS, the following filters should still work:

    For restrict_manage_posts hook now you will use:
    woocommerce_order_list_table_restrict_manage_orders

    Some others replacements hooks with HPOS:

    On High-Performance Order Storage documentation, there is a link to High Performance Order Storage Upgrade Recipe Book where you will find the path(s) to related core files you are looking for.

    In this documentation, you have:

    use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
    

    that points to woocommerce/src/Internal/DataStores/Orders, where OrdersTableQuery.php file is the right location to look at.

    Inside the method maybe_override_query() you have at line 233:

    $pre_query = apply_filters( 'woocommerce_hpos_pre_query', null, $this, $this->sql );
    

    Inside the method build_query() you have at line 877:

    $clauses = (array) apply_filters_ref_array( 'woocommerce_orders_table_query_clauses', array( $pieces, &$this, $this->args ) );
    

    And so on…