Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::get_sale_badge_html()protectedWC 1.0

Get the sale badge.

Method of the class: AbstractProductGrid{}

No Hooks.

Return

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() code WC 9.4.2

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>';
}