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

Product_Price::build_simple_product_priceprivateWC 1.0

Build price HTML for simple products.

Method of the class: Product_Price{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->build_simple_product_price( $product ): string;
$product(WC_Product) (required)
Product object.

Product_Price::build_simple_product_price() code WC 10.4.3

private function build_simple_product_price( \WC_Product $product ): string {
	$regular_price = wc_get_price_to_display( $product, array( 'price' => (float) $product->get_regular_price() ) );
	$sale_price    = $product->get_sale_price() !== '' ? wc_get_price_to_display( $product, array( 'price' => (float) $product->get_sale_price() ) ) : '';

	if ( empty( $regular_price ) ) {
		return '';
	}

	if ( $product->is_on_sale() && '' !== $sale_price ) {
		return sprintf(
			'<del style="text-decoration: line-through; font-size: 0.9em; margin-right: 0.5em;">%s</del><span>%s</span>',
			wc_price( $regular_price, array( 'in_span' => false ) ),
			wc_price( $sale_price, array( 'in_span' => false ) )
		);
	} else {
		return sprintf(
			'<span>%s</span>',
			wc_price( $regular_price, array( 'in_span' => false ) )
		);
	}
}