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
|
|
@ -99,6 +99,11 @@ class ProductSaleBadge extends AbstractBlock {
|
||||||
|
|
||||||
$post_id = $block->context['postId'];
|
$post_id = $block->context['postId'];
|
||||||
$product = wc_get_product( $post_id );
|
$product = wc_get_product( $post_id );
|
||||||
|
|
||||||
|
if ( ! $product ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$is_on_sale = $product->is_on_sale();
|
$is_on_sale = $product->is_on_sale();
|
||||||
|
|
||||||
if ( ! $is_on_sale ) {
|
if ( ! $is_on_sale ) {
|
||||||
|
|
|
@ -86,6 +86,11 @@ class ProductStockIndicator extends AbstractBlock {
|
||||||
|
|
||||||
$post_id = $block->context['postId'];
|
$post_id = $block->context['postId'];
|
||||||
$product = wc_get_product( $post_id );
|
$product = wc_get_product( $post_id );
|
||||||
|
|
||||||
|
if ( ! $product ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$is_in_stock = $product->is_in_stock();
|
$is_in_stock = $product->is_in_stock();
|
||||||
$is_on_backorder = $product->is_on_backorder();
|
$is_on_backorder = $product->is_on_backorder();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue