Automattic / woocommerce-subscriptions-core

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

Replace `wp_count_posts( 'shop_subscription' )` with new data store function to work with HPOS #388

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Fixes #382

Description

In #372 we introduced a new data store function that returns an array of subscription statuses and the number of subscriptions on the store with that status:

WC_Data_Store::load( 'subscription' )->get_subscriptions_count_by_status()

In this PR, I'm updating all uses of wp_count_posts() with this new data store function.

Notes

How to test this PR

To test the Admin System Status changes:

  1. Enable HPOS and purchase a handful of subscriptions
  2. Change some statuses of the subscriptions
  3. View WooCommerce > Status
  4. Scroll down to Subscriptions section and look at the Subscription Statuses: row.
  5. Disable HPOS and purchase some more subscriptions to test with HPOS disabled.

For the rest of the changes I ran the following snippet in WP Console and tested with HPOS enabled and disabled:

echo 'WC_Subscriptions::get_subscription_status_counts(): ' . var_export( WC_Subscriptions::get_subscription_status_counts(), true ) . "\n";

echo "\n\n";
delete_option( 'wcs_is_large_site' );

echo 'wcs_is_large_site(): ' . var_export( wcs_is_large_site(), true );

echo "\n\n";

echo 'WCS_Admin_System_Status::get_subscription_statuses(): ' . var_export( WCS_Admin_System_Status::get_subscription_statuses(), true );

Product impact