Product SKU: no render the prefix when the SKU isn't defined (https://github.com/woocommerce/woocommerce-blocks/pull/8837)

This commit is contained in:
Luigi Teschio 2023-03-23 15:08:48 +01:00 committed by GitHub
parent 48fde013ea
commit d5cb9b0248
1 changed files with 16 additions and 8 deletions

View File

@ -55,14 +55,22 @@ class ProductSKU extends AbstractBlock {
$post_id = $block->context['postId'];
$product = wc_get_product( $post_id );
if ( $product ) {
return sprintf(
'<div class="wc-block-components-product-sku wc-block-grid__product-sku">
SKU:
<strong>%s</strong>
</div>',
$product->get_sku()
);
if ( ! $product ) {
return '';
}
$product_sku = $product->get_sku();
if ( ! $product_sku ) {
return '';
}
return sprintf(
'<div class="wc-block-components-product-sku wc-block-grid__product-sku">
SKU:
<strong>%s</strong>
</div>',
$product_sku
);
}
}