Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Sale_Badge::build_badge_html
Build email-compatible badge HTML.
Метод класса: Product_Sale_Badge{}
Хуков нет.
Возвращает
Строку.
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_badge_html( $sale_text, $attributes, $rendering_context ): string;
- $sale_text(строка) (обязательный)
- Sale badge text.
- $attributes(массив) (обязательный)
- Block attributes.
- $rendering_context(Rendering_Context) (обязательный)
- Rendering context.
Код Product_Sale_Badge::build_badge_html() Product Sale Badge::build badge html WC 10.4.3
private function build_badge_html( string $sale_text, array $attributes, Rendering_Context $rendering_context ): string {
$align = $attributes['align'] ?? 'left';
$position_style = $this->get_position_style( $align );
$badge_styles = array_merge(
array(
'font-size' => '0.875em',
'padding' => '0.25em 0.75em',
'display' => 'inline-block',
'width' => 'fit-content',
'border' => '1px solid #43454b',
'border-radius' => '4px',
'box-sizing' => 'border-box',
'color' => '#43454b',
'background' => '#fff',
'text-align' => 'center',
'text-transform' => 'uppercase',
'font-weight' => '600',
'z-index' => '9',
'position' => 'static',
),
$position_style
);
$custom_styles = Styles_Helper::get_block_styles(
$attributes,
$rendering_context,
array( 'border', 'background-color', 'color', 'typography', 'spacing' )
);
$style_attr = \WP_Style_Engine::compile_css(
array_merge( $badge_styles, $custom_styles['declarations'] ?? array() ),
''
);
return sprintf(
'<span class="wc-block-components-product-sale-badge__text" style="%s">%s</span>',
esc_attr( $style_attr ),
esc_html( $sale_text )
);
}