Automattic / woocommerce-subscriptions-core

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

After processing an early renewal, make sure the suspension count meta is reset to 0 #539

Closed mattallan closed 7 months ago

mattallan commented 7 months ago

Description

In Woo Subscriptions we have a setting that limits the number of times a customer can suspend their subscription: image

We store the number of times a subscription is suspended in meta _suspension_count and whenever we process a renewal order, we reset this count back to 0. While testing 4584-gh-woocommerce/woocommerce-subscriptions I noticed that early renewals do not reset the _suspension_count meta because even though inside $subscription->payment_complete_for_order() we're calling $this->set_suspension_count( 0 );, we never actually call $subscription->save()...

The issue is we relied on $subscription->update_status( 'active' ); to call save() however this function only calls save if the status is actually updated and in the case of early renewals, the subscription status is not changed.

To fix this I've manually called save if we don't need to update the status of the subscription.

How to test this PR

  1. From the WC > Settings > Subscriptions page, enable early renewals and update the Customer Suspensions setting to any number greater than 1.
  2. Purchase an active subscription, then from the My Account > Subscriptions > view subscription, click on the "Suspend" action.
  3. Open the DB and confirm _suspension_count meta is 1.
  4. Reactivate the subscription and click on "Renew now" action.
  5. After renewing the subscription early, check in the DB to confirm the _suspension_count has been reset to 0.
  6. On trunk this number will remain 1, but on this branch it'll be reset back to 0.

Product impact