Fix order paid and completed dates to respect historical creation dates #183
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.
Summary
Fixes an issue where orders generated with historical dates (using
--date-startand--date-endflags) would have their paid and completed dates set to the current time instead of being based on the order's creation date.Problem
When generating orders with historical creation dates, the order generator was setting the paid and completed dates before the initial
$order->save()call. WooCommerce's status transition hooks during the save would override these dates with the current timestamp, resulting in orders with creation dates in the past but paid/completed dates of today.Solution
This PR moves the date-setting logic to after the initial order save. By setting the dates after the order has been created and its status set, we prevent WooCommerce from overriding them. The dates are now correctly calculated relative to the order's creation date:
Testing
Generate orders with historical dates and verify that paid and completed dates are now set relative to the creation date rather than the current time:
🤖 Generated with Claude Code