Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
85 stars 31 forks source link

[HPOS] Fix filtering the Amin Orders table by subscription related orders #356

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Fixes #199

Description

When you have HPOS enabled, clicking on a subscriptions related orders link on the Subscriptions table page (see below) would send you to the orders table but every order was being loaded (it should only list the order that relate to the subscription)

image

This PR fixes this issue as well as addresses some extra changes to improve HPOS compatibility.

To filter the orders table, we previously hooked onto the posts_where which doesn't work in HPOS therefore we need to use an equivalent hook found in the Automattic\WooCommerce\Internal\Admin\Orders\ListTable class.

woocommerce_shop_order_list_table_prepare_items_query_args

This hook is used to filter the List Orders table by modifying the args sent to wc_get_orders( $args ) so I created a new filter_orders_table_by_related_orders() function instead of trying to repurpose the existing function attached to the posts_where filter.

Because this new hook occurs at a different time, we can't add admin notices so I had to update display_renewal_filter_notice() to handle displaying the appropriate admin notices.

In this PR I also updated get_related_orders_link() to return the HPOS and non-HPOS Orders List table urls.

How to test this PR

  1. Enable HPOS on your store
  2. Purchase two or more subscriptions and process a bunch of renewals for one of the subscriptions
  3. From the WooCommerce > Subscriptions, click on one of the Related Order count link
  4. Make sure the Orders table is filtered to only show orders that belong to the subscription you clicked.
  5. On trunk, this table isn't filtered and all orders are being shown

Product impact