Return early if post status is `auto-draft` to prevent fatal.

While creating an order, if we remove an item after adding, `pre_post_update` hook gets called. Since the order is not created yet, `$order->get_date_created()` will be null, and this will cause a fatal in the event tracker which checks for and tracks edit in order created date.

We now return early when order status is `auto-draft` to prevent these kind of errors.
This commit is contained in:
vedanshujain 2019-07-17 00:21:18 +05:30
parent d034131781
commit 6ab03e6acd
1 changed files with 4 additions and 0 deletions

View File

@ -73,6 +73,10 @@ class WC_Orders_Tracking {
return;
}
if ( 'auto-draft' === get_post_status( $id ) ) {
return;
}
$order = wc_get_order( $id );
$date_created = $order->get_date_created()->date( 'Y-m-d H:i:s' );
// phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification