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 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 ) {