From 0d9d06cd4681ac71c519bbb7fb94b23653e2cf59 Mon Sep 17 00:00:00 2001 From: Manish Menaria Date: Tue, 22 Oct 2024 12:56:06 +0530 Subject: [PATCH] Fix: Upsells collection not showing correct products on frontend (#51730) * Fix: Upsells collection not showing correct products on frontend This commit addresses an issue where the Upsells collection wasn't displaying the correct products on the frontend. The problem was caused by a variable name mismatch in the condition checking for empty product references. * Add changefile(s) from automation for the following project(s): woocommerce * Rename product_references variable for consistency * Update variable name --------- Co-authored-by: github-actions Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> --- .../woocommerce/changelog/51730-fix-upsells-collection-issue | 4 ++++ .../woocommerce/src/Blocks/BlockTypes/ProductCollection.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/woocommerce/changelog/51730-fix-upsells-collection-issue diff --git a/plugins/woocommerce/changelog/51730-fix-upsells-collection-issue b/plugins/woocommerce/changelog/51730-fix-upsells-collection-issue new file mode 100644 index 00000000000..21d28e4bed5 --- /dev/null +++ b/plugins/woocommerce/changelog/51730-fix-upsells-collection-issue @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Product Collection: Fix Upsells collection not showing linked product on Frontend on Single Product Template \ No newline at end of file diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductCollection.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductCollection.php index d2b638375d8..b0bb4ee874a 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductCollection.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductCollection.php @@ -2053,7 +2053,7 @@ class ProductCollection extends AbstractBlock { function ( $collection_args, $query ) { $product_references = isset( $query['productReference'] ) ? array( $query['productReference'] ) : null; // Infer the product reference from the location if an explicit product is not set. - if ( empty( $product_reference ) ) { + if ( empty( $product_references ) ) { $location = $collection_args['productCollectionLocation']; if ( isset( $location['type'] ) && 'product' === $location['type'] ) { $product_references = array( $location['sourceData']['productId'] );