From f61646d1a2606aca4e0599225220eae118d48f6d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 18 Apr 2017 21:32:52 -0300 Subject: [PATCH 1/2] Only return product by SKU if published Fixes #14480 --- includes/data-stores/class-wc-product-data-store-cpt.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 4e3eb5c9788..ab598e35813 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -822,7 +822,9 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da FROM $wpdb->posts AS posts LEFT JOIN $wpdb->postmeta AS postmeta ON ( posts.ID = postmeta.post_id ) WHERE posts.post_type IN ( 'product', 'product_variation' ) - AND postmeta.meta_key = '_sku' AND postmeta.meta_value = '%s' + AND posts.post_status = 'publish' + AND postmeta.meta_key = '_sku' + AND postmeta.meta_value = '%s' LIMIT 1 ", $sku ) ); } From 0d46a89f83be138483f0447555e5f59f96367074 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 19 Apr 2017 14:27:19 -0300 Subject: [PATCH 2/2] Check only if is not in trash --- includes/data-stores/class-wc-product-data-store-cpt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index ab598e35813..303a1a79952 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -822,7 +822,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da FROM $wpdb->posts AS posts LEFT JOIN $wpdb->postmeta AS postmeta ON ( posts.ID = postmeta.post_id ) WHERE posts.post_type IN ( 'product', 'product_variation' ) - AND posts.post_status = 'publish' + AND posts.post_status != 'trash' AND postmeta.meta_key = '_sku' AND postmeta.meta_value = '%s' LIMIT 1