Product Gallery Thumbnails: Only output thumbnails markup when multiple product thumbnails are present (https://github.com/woocommerce/woocommerce-blocks/pull/10761)
* Fix "On sale" badge class for shop * Add class to sale badge * Product Gallery Thumbnails: Remove empty markup from the frontend when no thumbnails are present * Product Gallery Thumbnails: Minor null coalescing operator improvement * Product Gallery Thumbnails: Remove the Thumbnails markup if there's only one image present * Product Gallery Thumbnails: Minor null coalescing operator improvement --------- Co-authored-by: Alba Rincón <alba.rincon@automattic.com> Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
This commit is contained in:
parent
35e82fe4ec
commit
e29684e4ab
|
@ -5,7 +5,7 @@ use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
|
||||||
use Automattic\WooCommerce\Blocks\Utils\ProductGalleryUtils;
|
use Automattic\WooCommerce\Blocks\Utils\ProductGalleryUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductGalleryLargeImage class.
|
* ProductGalleryThumbnails class.
|
||||||
*/
|
*/
|
||||||
class ProductGalleryThumbnails extends AbstractBlock {
|
class ProductGalleryThumbnails extends AbstractBlock {
|
||||||
/**
|
/**
|
||||||
|
@ -49,15 +49,14 @@ class ProductGalleryThumbnails extends AbstractBlock {
|
||||||
|
|
||||||
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
|
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
|
||||||
|
|
||||||
$post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : '';
|
$post_id = $block->context['postId'] ?? '';
|
||||||
$product = wc_get_product( $post_id );
|
$product = wc_get_product( $post_id );
|
||||||
$post_thumbnail_id = $product->get_image_id();
|
|
||||||
$html = '';
|
|
||||||
|
|
||||||
if ( $product ) {
|
if ( $product ) {
|
||||||
$post_thumbnail_id = $product->get_image_id();
|
$post_thumbnail_id = $product->get_image_id();
|
||||||
$product_gallery_images = ProductGalleryUtils::get_product_gallery_images( $post_id, 'thumbnail', array() );
|
$product_gallery_images = ProductGalleryUtils::get_product_gallery_images( $post_id, 'thumbnail', array() );
|
||||||
if ( $product_gallery_images && $post_thumbnail_id ) {
|
if ( $product_gallery_images && $post_thumbnail_id ) {
|
||||||
|
$html = '';
|
||||||
$number_of_thumbnails = isset( $block->context['thumbnailsNumberOfThumbnails'] ) ? $block->context['thumbnailsNumberOfThumbnails'] : 3;
|
$number_of_thumbnails = isset( $block->context['thumbnailsNumberOfThumbnails'] ) ? $block->context['thumbnailsNumberOfThumbnails'] : 3;
|
||||||
$thumbnails_count = 1;
|
$thumbnails_count = 1;
|
||||||
|
|
||||||
|
@ -83,7 +82,6 @@ class ProductGalleryThumbnails extends AbstractBlock {
|
||||||
|
|
||||||
$thumbnails_count++;
|
$thumbnails_count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<div class="wc-block-components-product-gallery-thumbnails wp-block-woocommerce-product-gallery-thumbnails %1$s" style="%2$s">
|
'<div class="wc-block-components-product-gallery-thumbnails wp-block-woocommerce-product-gallery-thumbnails %1$s" style="%2$s">
|
||||||
|
@ -95,5 +93,7 @@ class ProductGalleryThumbnails extends AbstractBlock {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue