Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Price::generate_price_htmlprivateWC 1.0

Generate clean price HTML from product data.

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

Хуков нет.

Возвращает

Строку.

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

// private - только в коде основоного (родительского) класса
$result = $this->generate_price_html( $product, $attributes, $rendering_context ): string;
$product(WC_Product) (обязательный)
Product object.
$attributes(массив) (обязательный)
Block attributes.
$rendering_context(Rendering_Context) (обязательный)
Rendering context.

Код Product_Price::generate_price_html() WC 10.4.3

private function generate_price_html( \WC_Product $product, array $attributes, Rendering_Context $rendering_context ): string {
	$price_html = $this->build_price_from_scratch( $product );

	if ( empty( $price_html ) ) {
		return '';
	}

	$price_styles = array(
		'display'         => 'block',
		'margin'          => '0',
		'padding'         => '0',
		'font-family'     => 'inherit',
		'color'           => 'inherit',
		'text-decoration' => 'none',
	);

	$custom_styles = Styles_Helper::get_block_styles( $attributes, $rendering_context, array( 'border', 'background-color', 'color', 'typography', 'spacing' ) );
	$price_styles  = array_merge( $price_styles, $custom_styles['declarations'] );

	$style_attr = \WP_Style_Engine::compile_css( $price_styles, '' );

	return sprintf(
		'<div class="wc-block-components-product-price" style="%s">%s</div>',
		esc_attr( $style_attr ),
		$price_html
	);
}