This PR requires the changes in #336 to backfill the start date. The existing code checks if the start date is set, whereas it use to check if it is empty. #336 includes the changes which honours the old behavior of checking if the star date is empty not isset.
Description
When a new subscription is created via the admin screen, WC creates a new subscription in setup_action_new_order().
That function creates the subscription via new WC_Subscription(). Eventually that newly created subscription instance is passed around to all the metabox functions and used to populate the edit screen.
However when it gets to the subscription schedule metabox, this HPOS approach changed the existing behaviour because we almost always use to get a fresh instance of the subscription via the global post ID, now with an instance of the subscription, this was no longer necessary. There was a small reason to still get the subscription, however.
When a subscription is created, it doesn't have a start date by default. When you load (read) a subscription with no start date, we set it to the date the subscription was created.
And so, before these changes, if you went to the admin subscriptions list table and clicked Add new you'd get an edit subscription screen with no start date pre-populated.
This PR fixes that by making sure we do a read on the subscription if the start date is empty indicating that the subscription is brand new. This will trigger the start date to be backfilled with the created date and we're back to how this use to work.
Because the start date wasn't being pre-populated, youd get the following error when you'd save the subscription:
PHP Warning: Undefined array key "start" in public/wp-content/plugins/woocommerce-subscriptions-core/includes/class-wc-subscription.php on line 2459
How to test this PR
Enable HPOS tables.
Go to WooCommerce > Subscriptions > Add new
Note the subscription start date is empty.
Add items, a customer etc and click Save.
You should get the error message mentioned above.
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
Fixes #361
π Blocked by https://github.com/Automattic/woocommerce-subscriptions-core/pull/336 πThis PR requires the changes in #336 to backfill the start date. The existing code checks if the start date is set, whereas it use to check if it is empty. #336 includes the changes which honours the old behavior of checking if the star date is empty not isset.Description
When a new subscription is created via the admin screen, WC creates a new subscription in
setup_action_new_order()
.That function creates the subscription via
new WC_Subscription()
. Eventually that newly created subscription instance is passed around to all the metabox functions and used to populate the edit screen.However when it gets to the subscription schedule metabox, this HPOS approach changed the existing behaviour because we almost always use to get a fresh instance of the subscription via the global post ID, now with an instance of the subscription, this was no longer necessary. There was a small reason to still get the subscription, however.
When a subscription is created, it doesn't have a start date by default. When you load (read) a subscription with no start date, we set it to the date the subscription was created.
And so, before these changes, if you went to the admin subscriptions list table and clicked Add new you'd get an edit subscription screen with no start date pre-populated.
This PR fixes that by making sure we do a read on the subscription if the start date is empty indicating that the subscription is brand new. This will trigger the start date to be backfilled with the created date and we're back to how this use to work.
Because the start date wasn't being pre-populated, youd get the following error when you'd save the subscription:
How to test this PR
Product impact