Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::render_anchorprivateWC 1.0

Render anchor.

Метод класса: ProductImage{}

Хуков нет.

Возвращает

Строку.

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

// private - только в коде основоного (родительского) класса
$result = $this->render_anchor( $product, $on_sale_badge, $product_image, $attributes, $inner_blocks_content );
$product(WC_Product) (обязательный)
Product object.
$on_sale_badge(строка) (обязательный)
Return value from $render_image.
$product_image(строка) (обязательный)
Return value from $render_on_sale_badge.
$attributes(массив) (обязательный)
Attributes.
$inner_blocks_content(строка) (обязательный)
Rendered HTML of inner blocks.

Код ProductImage::render_anchor() WC 10.4.0

private function render_anchor( $product, $on_sale_badge, $product_image, $attributes, $inner_blocks_content ) {
	$product_permalink = $product->get_permalink();

	$is_link        = isset( $attributes['showProductLink'] ) ? $attributes['showProductLink'] : true;
	$href_attribute = $is_link ? sprintf( 'href="%s"', esc_url( $product_permalink ) ) : 'href="#" onclick="return false;"';
	$wrapper_style  = ! $is_link ? 'pointer-events: none; cursor: default;' : '';
	$directive      = $is_link ? 'data-wp-on--click="woocommerce/product-collection::actions.viewProduct"' : '';

	$inner_blocks_container = sprintf(
		'<div class="wc-block-components-product-image__inner-container">%s</div>',
		$inner_blocks_content
	);

	return sprintf(
		'<a %1$s style="%2$s" %3$s>%4$s%5$s%6$s</a>',
		$href_attribute,
		esc_attr( $wrapper_style ),
		$directive,
		$on_sale_badge,
		$product_image,
		$inner_blocks_container
	);
}