In Woo Subscriptions we have a setting that limits the number of times a customer can suspend their subscription:
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
From the WC > Settings > Subscriptions page, enable early renewals and update the Customer Suspensions setting to any number greater than 1.
Purchase an active subscription, then from the My Account > Subscriptions > view subscription, click on the "Suspend" action.
Open the DB and confirm _suspension_count meta is 1.
Reactivate the subscription and click on "Renew now" action.
After renewing the subscription early, check in the DB to confirm the _suspension_count has been reset to 0.
On trunk this number will remain 1, but on this branch it'll be reset back to 0.
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Description
In Woo Subscriptions we have a setting that limits the number of times a customer can suspend their subscription:![image](https://github.com/Automattic/woocommerce-subscriptions-core/assets/2275145/a10ce4ed-eb5a-4efd-abf6-0d17eb5dd096)
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 callsave()
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
_suspension_count
meta is1
._suspension_count
has been reset to 0.trunk
this number will remain 1, but on this branch it'll be reset back to 0.Product impact