diff --git a/includes/class-woocommerce-custom-orders-table-cli.php b/includes/class-woocommerce-custom-orders-table-cli.php index 3d8ee31..636ec62 100644 --- a/includes/class-woocommerce-custom-orders-table-cli.php +++ b/includes/class-woocommerce-custom-orders-table-cli.php @@ -93,15 +93,29 @@ public function migrate( $args = array(), $assoc_args = array() ) { while ( ! empty( $order_data ) ) { foreach ( $order_data as $order_id ) { $order = wc_get_order( $order_id ); - $result = $order->get_data_store()->populate_from_meta( $order ); - - if ( is_wp_error( $result ) ) { - return WP_CLI::error( sprintf( - /* Translators: %1$d is the order ID, %2$s is the error message. */ - 'A database error occurred while migrating order %1$d: %2$s.', - $order_id, - $result->get_error_message() + + if ( ! $order ) { + // NOTE We can't get the error message unfortunately due to the underlying code in + // WC_Order_Factory::get_order(). It catches the exception and just returns false. + // Issue has been raised on WC - https://github.com/woocommerce/woocommerce/issues/15616 + + WP_CLI::warning( sprintf( + /* Translators: %1$d is the order ID. */ + 'There was an error getting %1$d.', + $order_id ) ); + } else { + + $result = $order->get_data_store()->populate_from_meta( $order ); + + if ( is_wp_error( $result ) ) { + return WP_CLI::error( sprintf( + /* Translators: %1$d is the order ID, %2$s is the error message. */ + 'A database error occurred while migrating order %1$d: %2$s.', + $order_id, + $result->get_error_message() + ) ); + } } $processed++;