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 00000000000..b615f2f51e9 --- /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 6f94345ae07..55e95ccca87 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php @@ -111,7 +111,7 @@ class ProductRating extends AbstractBlock { 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 39867d5d7cd..1475a005217 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSKU.php @@ -54,7 +54,7 @@ class ProductSKU extends AbstractBlock { 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 1a6501221a1..5bd428d21e2 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php @@ -97,7 +97,7 @@ class ProductSaleBadge extends AbstractBlock { 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 bc0968ea827..867d6d9d50a 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php @@ -84,7 +84,7 @@ class ProductStockIndicator extends AbstractBlock { return $content; } - $post_id = $block->context['postId']; + $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); if ( ! $product ) {