Automattic\WooCommerce\Blocks\BlockTypes
ProductImage::render_on_sale_badge
Render on Sale Badge.
Method of the class: ProductImage{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->render_on_sale_badge( $product, $attributes );
- $product(WC_Product) (required)
- Product object.
- $attributes(array) (required)
- Attributes.
ProductImage::render_on_sale_badge() ProductImage::render on sale badge code WC 10.3.5
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();
}