Product Rating: Remove empty markup if no ratings are present (https://github.com/woocommerce/woocommerce-blocks/pull/9822)
* Product Rating: Remove empty markup if no real or mocked ratings are present * Fix TS errors * Remove unrelated TS fixes
This commit is contained in:
parent
a2d09319a7
commit
254c7e8086
|
@ -134,7 +134,7 @@ interface ProductRatingProps {
|
|||
shouldDisplayMockedReviewsWhenProductHasNoReviews: boolean;
|
||||
}
|
||||
|
||||
export const Block = ( props: ProductRatingProps ): JSX.Element | null => {
|
||||
export const Block = ( props: ProductRatingProps ): JSX.Element | undefined => {
|
||||
const {
|
||||
textAlign,
|
||||
isDescendentOfSingleProductBlock,
|
||||
|
@ -168,16 +168,18 @@ export const Block = ( props: ProductRatingProps ): JSX.Element | null => {
|
|||
mockedRatings
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={ className } style={ styleProps.style }>
|
||||
<div className="wc-block-components-product-rating__container">
|
||||
{ content }
|
||||
{ reviews && isDescendentOfSingleProductBlock ? (
|
||||
<ReviewsCount reviews={ reviews } />
|
||||
) : null }
|
||||
if ( reviews || shouldDisplayMockedReviewsWhenProductHasNoReviews ) {
|
||||
return (
|
||||
<div className={ className } style={ styleProps.style }>
|
||||
<div className="wc-block-components-product-rating__container">
|
||||
{ content }
|
||||
{ reviews && isDescendentOfSingleProductBlock ? (
|
||||
<ReviewsCount reviews={ reviews } />
|
||||
) : null }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default withProductDataContext( Block );
|
||||
|
|
|
@ -105,7 +105,7 @@ class ProductRating extends AbstractBlock {
|
|||
$post_id = $block->context['postId'];
|
||||
$product = wc_get_product( $post_id );
|
||||
|
||||
if ( $product ) {
|
||||
if ( $product && $product->get_review_count() > 0 ) {
|
||||
$product_reviews_count = $product->get_review_count();
|
||||
$product_rating = $product->get_average_rating();
|
||||
$parsed_attributes = $this->parse_attributes( $attributes );
|
||||
|
@ -202,5 +202,6 @@ class ProductRating extends AbstractBlock {
|
|||
$rating_html
|
||||
);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue