Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::render_on_sale_badge()privateWC 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 8.7.0

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

	$font_size = StyleAttributesUtils::get_font_size_class_and_style( $attributes );

	$on_sale_badge = sprintf(
		'
	<div class="wc-block-components-product-sale-badge wc-block-components-product-sale-badge--align-%s wc-block-grid__product-onsale %s" style="%s">
		<span aria-hidden="true">%s</span>
		<span class="screen-reader-text">Product on sale</span>
	</div>
',
		esc_attr( $attributes['saleBadgeAlign'] ),
		isset( $font_size['class'] ) ? esc_attr( $font_size['class'] ) : '',
		isset( $font_size['style'] ) ? esc_attr( $font_size['style'] ) : '',
		esc_html__( 'Sale', 'woocommerce' )
	);
	return $on_sale_badge;
}