diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php index 93f3eb33bf3..2125b75fc50 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php @@ -432,6 +432,26 @@ class WC_Admin_Reports_Sync { * @return void */ public static function orders_lookup_import_order( $order_id ) { + + $order = wc_get_order( $order_id ); + + // If the order isn't found for some reason, skip the sync. + if ( ! $order ) { + return; + } + + $type = $order->get_type(); + + // If the order isn't the right type, skip sync. + if ( 'shop_order' !== $type && 'shop_order_refund' !== $type ) { + return; + } + + // If the order has no id or date created, skip sync. + if ( ! $order->get_id() || ! $order->get_date_created() ) { + return; + } + $result = array_sum( array( WC_Admin_Reports_Orders_Stats_Data_Store::sync_order( $order_id ), diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php index 1928a51b59a..4165a982a71 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php @@ -358,6 +358,10 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im $order = wc_get_order( $order_id ); + if ( ! $order ) { + return -1; + } + // Refunds don't affect coupon stats so return successfully if one is called here. if ( 'shop_order_refund' === $order->get_type() ) { return true; diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php index 233ff99a95d..15d7c22f92a 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php @@ -311,7 +311,12 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl */ public static function sync_order_taxes( $order_id ) { global $wpdb; - $order = wc_get_order( $order_id ); + + $order = wc_get_order( $order_id ); + if ( ! $order ) { + return -1; + } + $tax_items = $order->get_items( 'tax' ); $num_updated = 0;