From ea033216674d65ff2097882593111aaef351e9de Mon Sep 17 00:00:00 2001 From: DanielWeiser <46303277+DanielWeiser@users.noreply.github.com> Date: Wed, 8 Jul 2020 15:54:34 +0300 Subject: [PATCH] Skip product if item not found by id --- src/include/class-wc-retailcrm-history.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 3ad26b3..886ac7f 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -610,6 +610,12 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : if ($product_data) { foreach ($product_data as $key => $product) { $item = retailcrm_get_wc_product($product['offer'][$this->bind_field], $this->retailcrm_settings); + if (!$item) { + $logger = new WC_Logger(); + $logger->add('retailcrm', 'Product not found by ' . $this->bind_field); + continue; + } + if ($product['discountTotal'] > 0) { $item->set_price($product['initialPrice'] - $product['discountTotal']); } @@ -885,4 +891,5 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : return $outputArray; } } -endif; + +endif; \ No newline at end of file