There exists a small chance that appears to have affected a handful of stores where renewal orders go straight to completed status rather than processing. We haven't been able to find the root cause of this but based on the theory outlined by @kaushikasomaiya in the issue description, it may be caused by code calling the needs_processing() function after we've created the order but before we've added the line items.
This causes WC to cache the needs_processing value in a transient, and therefore incorrectly determine that the order doesn't need processing even though the line items have changed since that original determination.
How to test this PR
Purchase a subscription with a product that does need processing (not downloadable).
Run the following code snippet.
// Hook into the order being created and call $order->needs_processing(); so it caches a false value (before items are added)
add_action( 'woocommerce_before_order_object_save', function( $order ) {
$order->needs_processing();
} );
// Create a renewal order. Replace the ID with your local Subscription ID.
$renewal_order = wcs_create_order_from_subscription( wcs_get_subscription( 4436 ), 'renewal_order' );
// Confirm the order needs processing.
var_export( $renewal_order->needs_processing() ); // False on `trunk` true on this branch.
On trunk you'll get the order doesn't need processing (false) and a completed order.
On this branch it will be true and the order will be processing as expected.
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 #517
Description
There exists a small chance that appears to have affected a handful of stores where renewal orders go straight to completed status rather than processing. We haven't been able to find the root cause of this but based on the theory outlined by @kaushikasomaiya in the issue description, it may be caused by code calling the
needs_processing()
function after we've created the order but before we've added the line items.This causes WC to cache the
needs_processing
value in a transient, and therefore incorrectly determine that the order doesn't need processing even though the line items have changed since that original determination.How to test this PR
trunk
you'll get the order doesn't need processing (false
) and a completed order.true
and the order will be processing as expected.Product impact