From 6ab03e6acd8583468a709dbad2c7ba98e48d9f4c Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Wed, 17 Jul 2019 00:21:18 +0530 Subject: [PATCH] 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. --- includes/tracks/events/class-wc-orders-tracking.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/tracks/events/class-wc-orders-tracking.php b/includes/tracks/events/class-wc-orders-tracking.php index 9b1bc56123d..ebd8ca48e93 100644 --- a/includes/tracks/events/class-wc-orders-tracking.php +++ b/includes/tracks/events/class-wc-orders-tracking.php @@ -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