From 78636b1f124572e36e25f3c732331a2722f93e1e Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 14 Jun 2018 14:52:25 +0100 Subject: [PATCH] Only cache if order ID is set. --- includes/data-stores/abstract-wc-order-data-store-cpt.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/data-stores/abstract-wc-order-data-store-cpt.php b/includes/data-stores/abstract-wc-order-data-store-cpt.php index f4dffe61a41..73ff2844cb0 100644 --- a/includes/data-stores/abstract-wc-order-data-store-cpt.php +++ b/includes/data-stores/abstract-wc-order-data-store-cpt.php @@ -324,7 +324,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme global $wpdb; // Get from cache if available. - $items = wp_cache_get( 'order-items-' . $order->get_id(), 'orders' ); + $items = 0 < $order->get_id() ? wp_cache_get( 'order-items-' . $order->get_id(), 'orders' ) : false; if ( false === $items ) { $items = $wpdb->get_results( @@ -333,7 +333,9 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme foreach ( $items as $item ) { wp_cache_set( 'item-' . $item->order_item_id, $item, 'order-items' ); } - wp_cache_set( 'order-items-' . $order->get_id(), $items, 'orders' ); + if ( 0 < $order->get_id() ) { + wp_cache_set( 'order-items-' . $order->get_id(), $items, 'orders' ); + } } $items = wp_list_filter( $items, array( 'order_item_type' => $type ) );