With HPOS + compatibility mode enabled, manually created subscriptions don't have a start date in the new order tables #514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes https://github.com/woocommerce/woocommerce-subscriptions/issues/4560
Description
When a store has both HPOS and compatibility mode enabled, there is some odd behaviour where new subscriptions are getting created with
_scheduled_start
meta stored as0
in thewp_wc_orders_meta
table and the correct start date in thewp_postmeta
.With HPOS enabled and compatibility mode disabled, the correct
_scheduled_start
is stored inwp_wc_orders_meta
so this issue just impacts those with the compatibility mode feature.The approach I've taken in this PR is to fix this by updating the
persist_order_to_db()
function inside our Subscriptions OrdersTable datastore class so that if theschedule_start
prop needs to be updated and it's empty, use the subscription's created date instead.We do similar behavior already in
init_order_record()
however, this function doesn't write the dates to the database as it's surrounded by$subscription->set_object_read( false );
.How to test this PR
Not sure if this is necessary but to flick between the different HPOS and compatibility mode settings, rather than waiting for the order data sync to finish, I just wipe my orders and subscriptions from the DB using the following queries:
trunk
verify that_scheduled_start
is set to0
in thewc_orders_meta
table but it is set to the correct value in thewp_postmeta
table for that same subscription_scheduled_start
has the same value inwc_orders_meta
andwp_postmeta
tablesOther tests:
_schedule_start
trunk
you'll notice there's no start date, on this branch there will be:Product impact