Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Fix issues with sorting the subscriptions list table on HPOS enabled sites #546

Closed james-allan closed 5 months ago

james-allan commented 7 months ago

Fixes #200 Fixes #471

Description

On HPOS enabled sites, filtering the subscriptions list table by the subscription's next payment, start, end, trial end, or last payment date all failed to correctly sort the table.

This originally required changes to WC core to fix, however with https://github.com/woocommerce/woocommerce/pull/36403 merged and released for some time, ordering the list table by meta value is now possible.

This PR makes use of those changes in WC to make sure we format the meta query args to ensure the list table is sorted by those meta values. Specially making sure we set the meta_key and meta_value order by properties.

eg:

array (
    ['limit'] => 20
    ['page'] => 1
    ['paginate'] => 1
    ['type'] => 'shop_subscription'
    ['orderby'] => 'meta_value' // <-- 
    ['order'] => 'DESC'
    ['meta_key'] => '_schedule_next_payment' // <--
)

How to test this PR

  1. Enable HPOS if it's not already enabled.
  2. Purchase a couple of subscriptions with various properties, end dates, varying next payment dates.
  3. Go to the admin subscriptions list table and order the list table by any of the columns.
    • eg next payment dates, end dates, last payment dates.
  4. On trunk you'll notice the table isn't correctly ordered.
  5. On this branch all ordering should work as expected.

Product impact

james-allan commented 7 months ago

Thanks for the review @Mayisha. I've fixed those issues. 😄