Prevent warning if there was no post ID available in some product elements (#45675)

* Prevent warning if there was no post ID available in some product elements

* Add changelog
This commit is contained in:
Karol Manijak 2024-03-20 14:49:02 +01:00 committed by GitHub
parent 55cd1982dc
commit a6500aa572
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Product Elements: fix some warning thrown when there was no post ID available

View File

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

View File

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

View File

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

View File

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