Automattic\WooCommerce\Blocks\BlockTypes
ProductGalleryLargeImageNextPrevious::render()
Include and render the block.
Method of the class: ProductGalleryLargeImageNextPrevious{}
No Hooks.
Return
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.
ProductGalleryLargeImageNextPrevious::render() ProductGalleryLargeImageNextPrevious::render code WC 9.8.2
protected function render( $attributes, $content, $block ) { $post_id = $block->context['postId']; if ( ! isset( $post_id ) ) { return ''; } $product = wc_get_product( $post_id ); if ( ! $product instanceof \WC_Product ) { return ''; } $product_gallery = $product->get_gallery_image_ids(); if ( empty( $product_gallery ) ) { return null; } $prev_button = $this->get_button( 'previous' ); $p = new \WP_HTML_Tag_Processor( $prev_button ); if ( $p->next_tag() ) { $p->set_attribute( 'data-wp-on--click', 'actions.selectPreviousImage' ); $p->set_attribute( 'aria-label', __( 'Previous image', 'woocommerce' ) ); $prev_button = $p->get_updated_html(); } $next_button = $this->get_button( 'next' ); $p = new \WP_HTML_Tag_Processor( $next_button ); if ( $p->next_tag() ) { $p->set_attribute( 'data-wp-on--click', 'actions.selectNextImage' ); $p->set_attribute( 'aria-label', __( 'Next image', 'woocommerce' ) ); $next_button = $p->get_updated_html(); } return strtr( '<div class="wc-block-product-gallery-large-image-next-previous wp-block-woocommerce-product-gallery-large-image-next-previous" data-wp-interactive=\'{data_wp_interactive}\' > <div class="wc-block-product-gallery-large-image-next-previous-container"> {prev_button} {next_button} </div> </div>', array( '{prev_button}' => $prev_button, '{next_button}' => $next_button, '{data_wp_interactive}' => 'woocommerce/product-gallery', ) ); }