Skip to content

Commit 2702baf

Browse files
authored
Merge pull request #143 from woocommerce/tweak/set-paid-and-completed-dates
Set paid and completed dates on orders
2 parents 4431276 + 590c778 commit 2702baf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

includes/Generator/Order.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public static function generate( $save = true, $assoc_args = array() ) {
8585
$fee->calculate_taxes( $calculate_tax_for );
8686
$order->add_item( $fee );
8787
}
88-
$order->set_status( self::get_status( $assoc_args ) );
88+
$status = self::get_status( $assoc_args );
89+
$order->set_status( $status );
8990
$order->calculate_totals( true );
9091

9192
$date = self::get_date_created( $assoc_args );
@@ -104,6 +105,18 @@ public static function generate( $save = true, $assoc_args = array() ) {
104105
OrderAttribution::add_order_attribution_meta( $order, $assoc_args );
105106
}
106107

108+
// Set paid and completed dates based on order status.
109+
if ( 'completed' === $status || 'processing' === $status ) {
110+
// Add random 0 to 36 hours to creation date.
111+
$date_paid = date( 'Y-m-d H:i:s', strtotime( $date ) + ( wp_rand( 0, 36 ) * HOUR_IN_SECONDS ) );
112+
$order->set_date_paid( $date_paid );
113+
if ( 'completed' === $status ) {
114+
// Add random 0 to 36 hours to paid date.
115+
$date_completed = date( 'Y-m-d H:i:s', strtotime( $date_paid ) + ( wp_rand( 0, 36 ) * HOUR_IN_SECONDS ) );
116+
$order->set_date_completed( $date_completed );
117+
}
118+
}
119+
107120
if ( $save ) {
108121
$order->save();
109122
}

0 commit comments

Comments
 (0)