Product Gallery: Add support for custom wrapper class parameter in the get_product_gallery_images() function. Fix the Product Gallery Thumbnails on click. (https://github.com/woocommerce/woocommerce-blocks/pull/11032)

This commit is contained in:
Daniel Dudzic 2023-09-22 21:04:01 +02:00 committed by GitHub
parent 13024c88e6
commit 0bab8f2067
3 changed files with 10 additions and 9 deletions

View File

@ -132,7 +132,8 @@ class ProductGalleryLargeImage extends AbstractBlock {
$main_images = ProductGalleryUtils::get_product_gallery_images(
$product_id,
'full',
$attributes
$attributes,
'wc-block-woocommerce-product-gallery-large-image__container'
);
$visible_main_image = array_shift( $main_images );

View File

@ -63,7 +63,7 @@ class ProductGalleryThumbnails extends AbstractBlock {
if ( $product ) {
$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(), 'wc-block-product-gallery-thumbnails__thumbnail' );
if ( $product_gallery_images && $post_thumbnail_id ) {
$html = '';
$number_of_thumbnails = isset( $block->context['thumbnailsNumberOfThumbnails'] ) ? $block->context['thumbnailsNumberOfThumbnails'] : 3;
@ -74,11 +74,9 @@ class ProductGalleryThumbnails extends AbstractBlock {
break;
}
$html .= '<div class="wc-block-product-gallery-thumbnails__thumbnail">';
$processor = new \WP_HTML_Tag_Processor( $product_gallery_image_html );
if ( $processor->next_tag() ) {
if ( $processor->next_tag( 'img' ) ) {
$processor->set_attribute(
'data-wc-on--click',
'actions.woocommerce.thumbnails.handleClick'
@ -87,8 +85,6 @@ class ProductGalleryThumbnails extends AbstractBlock {
$html .= $processor->get_updated_html();
}
$html .= '</div>';
$thumbnails_count++;
}

View File

@ -17,9 +17,10 @@ class ProductGalleryUtils {
* @param int $post_id Post ID.
* @param string $size Image size.
* @param array $attributes Attributes.
* @param string $wrapper_class Wrapper class.
* @return array
*/
public static function get_product_gallery_images( $post_id, $size = 'full', $attributes = array() ) {
public static function get_product_gallery_images( $post_id, $size = 'full', $attributes = array(), $wrapper_class = '' ) {
$product_gallery_images = array();
$product = wc_get_product( $post_id );
@ -35,7 +36,10 @@ class ProductGalleryUtils {
$attributes
);
$product_image_html = '<div class="wc-block-woocommerce-product-gallery-large-image__container">' . $product_image_html . '</div>';
if ( $wrapper_class ) {
$product_image_html = '<div class="' . $wrapper_class . '">' . $product_image_html . '</div>';
}
$product_image_html_processor = new \WP_HTML_Tag_Processor( $product_image_html );
$product_image_html_processor->next_tag( 'img' );
$product_image_html_processor->set_attribute(