Fix fatal error problems by no longer adding false to the list of orders

By adding this prevention, it also stops fatal errors (calling method on non-object) from happening down the line when working with the orders list that is always assumed to be a proper order object.

Example error this prevents:

```
Fatal error: Uncaught Error: Call to a member function get_items() on bool in /wp-content/plugins/woocommerce/includes/class-wc-order.php on line 1902
```
This commit is contained in:
Scott Kingsley Clark 2021-01-25 10:11:14 -06:00 committed by GitHub
parent ca4cc1d6f1
commit ceb3a0d753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -906,7 +906,14 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
$this->prime_order_item_caches_for_orders( $order_ids, $query_vars );
foreach ( $query->posts as $post ) {
$orders[] = wc_get_order( $post );
$order = wc_get_order( $post );
// If the order returns false, don't add it to the list.
if ( false === $order ) {
continue;
}
$orders[] = $order;
}
return $orders;