Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::render()protectedWC 1.0

Include and render the dynamic block.

{} Это метод класса: AbstractProductGrid{}

Хуков нет.

Возвращает

Строку. Rendered block type output.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render( $attributes, $content, $block );
$attributes(массив)
Block attributes.
По умолчанию: empty array
$content(строка)
Block content.
По умолчанию: empty string
$block(WP_Block|null)
Block instance.
По умолчанию: null

Код AbstractProductGrid::render() WC 7.1.0

protected function render( $attributes = array(), $content = '', $block = null ) {
	$this->attributes = $this->parse_attributes( $attributes );
	$this->content    = $content;
	$this->query_args = $this->parse_query_args();
	$products         = array_filter( array_map( 'wc_get_product', $this->get_products() ) );

	if ( ! $products ) {
		return '';
	}

	/**
	 * Override product description to prevent infinite loop.
	 *
	 * @see https://github.com/woocommerce/woocommerce-blocks/pull/6849
	 */
	foreach ( $products as $product ) {
		$product->set_description( '' );
	}

	/**
	 * Product List Render event.
	 *
	 * Fires a WP Hook named `experimental__woocommerce_blocks-product-list-render` on render so that the client
	 * can add event handling when certain products are displayed. This can be used by tracking extensions such
	 * as Google Analytics to track impressions.
	 *
	 * Provides the list of product data (shaped like the Store API responses) and the block name.
	 */
	$this->asset_api->add_inline_script(
		'wp-hooks',
		'
		window.addEventListener( "DOMContentLoaded", () => {
			wp.hooks.doAction(
				"experimental__woocommerce_blocks-product-list-render",
				{
					products: JSON.parse( decodeURIComponent( "' . esc_js(
			rawurlencode(
				wp_json_encode(
					array_map(
						[ StoreApi::container()->get( SchemaController::class )->get( 'product' ), 'get_item_response' ],
						$products
					)
				)
			)
		) . '" ) ),
					listName: "' . esc_js( $this->block_name ) . '"
				}
			);
		} );
		',
		'after'
	);

	return sprintf(
		'<div class="%s"><ul class="wc-block-grid__products">%s</ul></div>',
		esc_attr( $this->get_container_classes() ),
		implode( '', array_map( array( $this, 'render_product' ), $products ) )
	);
}