Automattic\WooCommerce\Blocks\BlockTypes

FeaturedProduct::render_attributesprotectedWC 1.0

Renders the featured product attributes.

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

Хуков нет.

Возвращает

Строку.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render_attributes( $product, $attributes );
$product(WC_Product) (обязательный)
Product object.
$attributes(массив) (обязательный)
Block attributes.
По умолчанию: empty array

Код FeaturedProduct::render_attributes() WC 10.5.0

protected function render_attributes( $product, $attributes ) {
	$output = '';

	// Backwards compatibility: Only render legacy attributes if `editMode` exists as boolean value
	// This allows us to distinguish between old and new version of the block (which accept inner blocks).
	if ( array_key_exists( 'editMode', $attributes ) && is_bool( $attributes['editMode'] ) ) {
		$legacy_title = sprintf(
			'<h2 class="wc-block-featured-product__title">%s</h2>',
			wp_kses_post( $product->get_title() )
		);
		if ( $product->is_type( ProductType::VARIATION ) ) {
			$legacy_title .= sprintf(
				'<h3 class="wc-block-featured-product__variation">%s</h3>',
				wp_kses_post( wc_get_formatted_variation( $product, true, true, false ) )
			);
		}

		$output .= $legacy_title;

		if (
			! isset( $attributes['showDesc'] ) ||
			( isset( $attributes['showDesc'] ) && false !== $attributes['showDesc'] )
		) {
			$desc_str = sprintf(
				'<div class="wc-block-featured-product__description">%s</div>',
				wc_format_content( wp_kses_post( $product->get_short_description() ? $product->get_short_description() : wc_trim_string( $product->get_description(), 400 ) ) )
			);
			$output  .= $desc_str;
		}

		if (
			! isset( $attributes['showPrice'] ) ||
			( isset( $attributes['showPrice'] ) && false !== $attributes['showPrice'] )
		) {
			$price_str = sprintf(
				'<div class="wc-block-featured-product__price">%s</div>',
				wp_kses_post( $product->get_price_html() )
			);
			$output   .= $price_str;
		}
	}

	return $output;
}