Automattic / woocommerce-subscriptions-core

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

Fixes updating all subscription payment methods when HPOS is enabled #349

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Fixes #128

Note To test this PR using WC Payments, you'll need to pull down these changes: https://github.com/Automattic/woocommerce-payments/pull/5254

Description

While testing https://github.com/Automattic/woocommerce-payments/pull/5254 I noticed updating all payment methods for subscriptions was still broken on stores that have HPOS enabled.

After some digging I found we still have a get_posts() inside our get_subscriptions_from_token() function. This PR updates this function to use wcs_get_orders_with_meta_query() so that this function works in both HPOS and non-HPOS.

How to test this PR

Testing with both HPOS and non HPOS enabled:

  1. Purchase two active subscriptions with WC Payments
  2. Go to My Account > Payment methods
  3. Add a new payment method (i used card number5555555555554444)
  4. After this card is added. Click "Make default"
  5. You should see a notice to update your subscriptions to use this new payment method
  6. Click "Yes"
  7. Go to My Account > Subscriptions and confirm all of your active subscriptions have the new payment method

When testing on trunk and HPOS enabled, you won't even see the notice to update all of your subscriptions, this is because the get_posts() doesn't work in HPOS.

Product impact

mattallan commented 1 year ago

Thank-you @shendy-a8c for the quick review on this one!