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)
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.
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
Enable HPOS on your store
Purchase two or more subscriptions and process a bunch of renewals for one of the subscriptions
From the WooCommerce > Subscriptions, click on one of the Related Order count link
Make sure the Orders table is filtered to only show orders that belong to the subscription you clicked.
On trunk, this table isn't filtered and all orders are being shown
Product impact
[x] Added changelog entry (or does not apply)
[x] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[x] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
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)
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 theAutomattic\WooCommerce\Internal\Admin\Orders\ListTable
class.This hook is used to filter the List Orders table by modifying the args sent to
wc_get_orders( $args )
so I created a newfilter_orders_table_by_related_orders()
function instead of trying to repurpose the existing function attached to theposts_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
trunk
, this table isn't filtered and all orders are being shownProduct impact