Closed james-allan closed 5 months ago
Do we want a changelog entry for this one? Maybe something like: ...
Sounds good. I've pushed in https://github.com/Automattic/woocommerce-subscriptions-core/pull/552/commits/9cc7f19554ad158075c37a10273ff47cda43f284
Fixes #494
Description
There are circumstances that can lead to errors like this one when processing renewals.
The cause is unknown. All we know is that for this error to occur
wcs_create_order_from_subscription()
must have failed to load the newly created order withwc_get_order()
which must have returnedfalse
. [code link]One known reason
wc_get_order()
will returnfalse
is an exception was thrown inWC_Order_Factory::get_order()
while the order was being read. What exception? Well we currently don't know because WC catches it, logs it viawc_caught_exception
.This PR improves this by hooking onto
woocommerce_caught_exception
when we're processing subscription related events. If an exception was caught by WC, we'll now log it on the scheduled action and in the failed scheduled action logs.Making that change alone wouldn't solve the
WCS_Related_Order_Store_Cached_CPT::add_relation
error I mentioned earlier.To fix that, I've changed
wcs_create_order_from_subscription()
so that if it fails to load the order, it will throw an exception, roll back the database, return aWP_Error
. If you follow that up the chain, that will then leadprocess_renewal()
to try another attempt to create the order. If that fails too, then it will throw an final error.How to test this PR
invalid order
exception.WCS_Related_Order_Store_Cached_CPT::add_relation()
error.Product impact