Fatal error when using Product Stock Indicator or On Sale Badge blocks on a homepage (#45135)
* Prevent accessing product if there's no product yet in ProductStockIndicator block * Prevent accessing product if there's no product yet in ProductSaleBadge block * Add changelog * Fix linter
This commit is contained in:
parent
382bcdf511
commit
d833e92f05
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Products Stock Indicator and Sale Badge: prevent fatal when block were used in a homepage
|
|
@ -97,8 +97,13 @@ class ProductSaleBadge extends AbstractBlock {
|
|||
return $content;
|
||||
}
|
||||
|
||||
$post_id = $block->context['postId'];
|
||||
$product = wc_get_product( $post_id );
|
||||
$post_id = $block->context['postId'];
|
||||
$product = wc_get_product( $post_id );
|
||||
|
||||
if ( ! $product ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$is_on_sale = $product->is_on_sale();
|
||||
|
||||
if ( ! $is_on_sale ) {
|
||||
|
|
|
@ -84,8 +84,13 @@ class ProductStockIndicator extends AbstractBlock {
|
|||
return $content;
|
||||
}
|
||||
|
||||
$post_id = $block->context['postId'];
|
||||
$product = wc_get_product( $post_id );
|
||||
$post_id = $block->context['postId'];
|
||||
$product = wc_get_product( $post_id );
|
||||
|
||||
if ( ! $product ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$is_in_stock = $product->is_in_stock();
|
||||
$is_on_backorder = $product->is_on_backorder();
|
||||
|
||||
|
|
Loading…
Reference in New Issue