From 8095482f691f97ca85c155d109bac132bbb1280c Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Wed, 4 Aug 2021 12:14:20 +0200 Subject: [PATCH] Fix: the same set of related products is always displayed get_related_products_query in the WC_Product_Data_Store_CPT class is querying the suitable products with a "limit" clause, this causes that products down in the table are never picked for display. This commit adds a ORDER BY RAND() to the query so that all products have a chance to get picked. --- includes/data-stores/class-wc-product-data-store-cpt.php | 2 ++ 1 file changed, 2 insertions(+) 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 190749d7db3..25ca18d6515 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -1315,6 +1315,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da AND p.post_type = 'product' ", + 'orderby' => ' + ORDER BY RAND()', 'limits' => ' LIMIT ' . absint( $limit ) . ' ',