Skip to content

Conversation

@layoutd
Copy link
Contributor

@layoutd layoutd commented Oct 24, 2025

Summary

Fixes an issue where orders generated with historical dates (using --date-start and --date-end flags) 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:

  • Paid date: 0-36 hours after creation date
  • Completed date: 0-36 hours after paid 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:

wp wc generate orders 10 --date-start=2024-01-01 --date-end=2024-12-31 --status=completed

🤖 Generated with Claude Code

Previously, when generating orders with historical dates, the paid and
completed dates would be set to the current time instead of being based
on the order's creation date. This was because WooCommerce's status
transition hooks would override these dates during the initial save.

This fix moves the date-setting logic to after the initial order save,
preventing WooCommerce from overriding the historical dates. The dates
are now correctly set relative to the order's creation date (paid date
is 0-36 hours after creation, completed date is 0-36 hours after paid).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@layoutd layoutd self-assigned this Oct 24, 2025
@layoutd
Copy link
Contributor Author

layoutd commented Oct 24, 2025

The issue is with refund dates so will be solved directly in #182

@layoutd layoutd closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants