Automattic\WooCommerce\Blocks\BlockTypes
AbstractProductGrid::get_sale_badge_html
Get the sale badge.
Method of the class: AbstractProductGrid{}
No Hooks.
Returns
String. Rendered product output.
Usage
// protected - for code of main (parent) or child class $result = $this->get_sale_badge_html( $product );
- $product(WC_Product) (required)
- Product.
AbstractProductGrid::get_sale_badge_html() AbstractProductGrid::get sale badge html code WC 10.7.0
protected function get_sale_badge_html( $product ) {
if ( empty( $this->attributes['contentVisibility']['price'] ) ) {
return '';
}
if ( empty( $this->attributes['contentVisibility']['image'] ) ) {
return '';
}
if ( ! $product->is_on_sale() ) {
return;
}
return '<div class="wc-block-grid__product-onsale">
<span aria-hidden="true">' . esc_html__( 'Sale', 'woocommerce' ) . '</span>
<span class="screen-reader-text">' . esc_html__( 'Product on sale', 'woocommerce' ) . '</span>
</div>';
}