Automattic\WooCommerce\Blocks\BlockTypes
ProductGalleryPager::render()
Include and render the block.
Method of the class: ProductGalleryPager{}
No Hooks.
Returns
String
. Rendered block type output.
Usage
// protected - for code of main (parent) or child class $result = $this->render( $attributes, $content, $block );
- $attributes(array) (required)
- Block attributes.
Default: empty array - $content(string) (required)
- Block content.
Default: empty string - $block(WP_Block) (required)
- Block instance.
ProductGalleryPager::render() ProductGalleryPager::render code WC 9.8.5
protected function render( $attributes, $content, $block ) { $post_id = $block->context['postId'] ?? ''; if ( ! $post_id ) { return ''; } $product = wc_get_product( $post_id ); if ( ! $product ) { return ''; } $product_gallery_images_ids = ProductGalleryUtils::get_product_gallery_image_ids( $product ); $total_images = count( $product_gallery_images_ids ); if ( 0 === $total_images ) { return ''; } $styles_and_classes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes ); $classes = $styles_and_classes['classes'] ?? ''; $styles = $styles_and_classes['styles'] ?? ''; return sprintf( '<div class="wc-block-product-gallery-pager %1$s" style="%2$s"> <span class="wc-block-product-gallery-pager__current-index" data-wp-text="context.selectedImageNumber"></span>/<span class="wc-block-product-gallery-pager__total-images">%3$s</span> </div>', $classes, $styles, $total_images, ); }