From 73d4a0d31c7a7e268cdf78588bd915741fc8c38a Mon Sep 17 00:00:00 2001 From: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:52:22 +0100 Subject: [PATCH 1/2] Prevent warning if there was no post ID available in some product elements --- plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php | 2 +- plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php | 2 +- plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php | 2 +- .../woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php index 6f94345ae071..55e95ccca87c 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php @@ -111,7 +111,7 @@ protected function render( $attributes, $content, $block ) { return $content; } - $post_id = $block->context['postId']; + $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); if ( $product && $product->get_review_count() > 0 ) { diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php index 39867d5d7cd3..1475a005217b 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php @@ -54,7 +54,7 @@ protected function render( $attributes, $content, $block ) { return $content; } - $post_id = $block->context['postId']; + $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); if ( ! $product ) { diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php index 1a6501221a11..5bd428d21e28 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php @@ -97,7 +97,7 @@ protected function render( $attributes, $content, $block ) { return $content; } - $post_id = $block->context['postId']; + $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); if ( ! $product ) { diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php index bc0968ea8275..867d6d9d50ac 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php @@ -84,7 +84,7 @@ protected function render( $attributes, $content, $block ) { return $content; } - $post_id = $block->context['postId']; + $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); if ( ! $product ) { From 37d4491f0e17ca3b2b0fb11e2b1271545275d1fe Mon Sep 17 00:00:00 2001 From: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:38:59 +0100 Subject: [PATCH 2/2] Add changelog --- .../woocommerce/changelog/fix-warnings-from-product-elements | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/woocommerce/changelog/fix-warnings-from-product-elements diff --git a/plugins/woocommerce/changelog/fix-warnings-from-product-elements b/plugins/woocommerce/changelog/fix-warnings-from-product-elements new file mode 100644 index 000000000000..b615f2f51e9d --- /dev/null +++ b/plugins/woocommerce/changelog/fix-warnings-from-product-elements @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Product Elements: fix some warning thrown when there was no post ID available