Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::render_on_sale_badgeprivateWC 1.0

Render on Sale Badge.

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

Хуков нет.

Возвращает

Строку.

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

// private - только в коде основоного (родительского) класса
$result = $this->render_on_sale_badge( $product, $attributes );
$product(WC_Product) (обязательный)
Product object.
$attributes(массив) (обязательный)
Attributes.

Код ProductImage::render_on_sale_badge() WC 10.5.2

private function render_on_sale_badge( $product, $attributes ) {
	if (
		! $product->is_on_sale()
		|| ! isset( $attributes['showSaleBadge'] )
		|| ( isset( $attributes['showSaleBadge'] ) && false === $attributes['showSaleBadge'] )
	) {
		return '';
	}

	$align = $attributes['saleBadgeAlign'] ?? 'right';

	$block = new \WP_Block(
		array(
			'blockName' => 'woocommerce/product-sale-badge',
			'attrs'     => array(
				'align' => $align,
			),
		),
		array(
			'postId' => $product->get_id(),
		)
	);

	return $block->render();
}