Automattic / woocommerce-subscriptions-core

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

Replace DB query in `WCS_Admin_System_Status::get_subscriptions_by_gateway()` to support HPOS #384

Closed Jinksi closed 1 year ago

Jinksi commented 1 year ago

Describe the bug

The WCS_Admin_System_Status::get_subscriptions_by_gateway() function uses a call to $wpdb->get_results( that will not work with HPOS-enabled stores.

This results in incorrect/missing results when rendering Subscriptions by Payment Gateway in WooCommerce → Status.

https://github.com/Automattic/woocommerce-subscriptions-core/blob/07d4d4f93a5d285693d0409a1c39fa68b0629fd9/includes/admin/class-wcs-admin-system-status.php#L364

It is also used by the WCS Rest API.

To Reproduce

  1. Enable HPOS + no syncing.
  2. Purchase a few subscriptions with 1 or more payment gateways.
  3. Change the status of 1 or more subscriptions (e.g. move to trash, cancel, place on hold).
  4. Note the count by status in WooCommerce → Subscriptions. image
  5. Go to WooCommerce → Status and find Subscriptions by Payment Gateway.
  6. Notice that these results are not correct.

Expected behavior

Subscriptions by Payment Gateway in WooCommerce → Status should display the correct count by status for each payment gateway when HPOS is enabled, and syncing is disabled.

Actual behavior

Subscriptions by Payment Gateway in WooCommerce → Status does not display the correct count by status for each payment gateway when HPOS is enabled, and syncing is disabled.

Product impact

Additional context