Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Sale_Badge::render_contentprotectedWC 1.0

Render the product sale badge block content for email.

Method of the class: Product_Sale_Badge{}

Hooks from the method

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_content( $block_content, $parsed_block, $rendering_context ): string;
$block_content(string) (required)
Block content.
$parsed_block(array) (required)
Parsed block.
$rendering_context(Rendering_Context) (required)
Rendering context.

Product_Sale_Badge::render_content() code WC 10.4.3

protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
	$product = $this->get_product_from_context( $parsed_block );
	if ( ! $product ) {
		return '';
	}

	if ( ! $product->is_on_sale() ) {
		return '';
	}

	$attributes = $parsed_block['attrs'] ?? array();

	/**
	 * Filters the product sale badge text.
	 *
	 * @hook woocommerce_sale_badge_text
	 * @since 10.0.0
	 *
	 * @param string $sale_text The sale badge text.
	 * @param \WC_Product $product The product object.
	 * @return string The filtered sale badge text.
	 */
	$sale_text = apply_filters( 'woocommerce_sale_badge_text', __( 'Sale', 'woocommerce' ), $product );

	$badge_html = $this->build_badge_html( $sale_text, $attributes, $rendering_context );
	return $this->apply_email_wrapper( $badge_html, $parsed_block );
}