wc_format_sale_price()WC 3.0.0

Format a sale price for display.

Хуки из функции

Возвращает

Строку.

Использование

wc_format_sale_price( $regular_price, $sale_price );
$regular_price(строка) (обязательный)
Regular price.
$sale_price(строка) (обязательный)
Sale price.

Список изменений

С версии 3.0.0 Введена.

Код wc_format_sale_price() WC 9.6.1

function wc_format_sale_price( $regular_price, $sale_price ) {
	// Format the prices.
	$formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
	$formatted_sale_price    = is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price;

	// Strikethrough pricing.
	$price = '<del aria-hidden="true">' . $formatted_regular_price . '</del> ';

	// For accessibility (a11y) we'll also display that information to screen readers.
	$price .= '<span class="screen-reader-text">';
	// translators: %s is a product's regular price.
	$price .= esc_html( sprintf( __( 'Original price was: %s.', 'woocommerce' ), wp_strip_all_tags( $formatted_regular_price ) ) );
	$price .= '</span>';

	// Add the sale price.
	$price .= '<ins aria-hidden="true">' . $formatted_sale_price . '</ins>';

	// For accessibility (a11y) we'll also display that information to screen readers.
	$price .= '<span class="screen-reader-text">';
	// translators: %s is a product's current (sale) price.
	$price .= esc_html( sprintf( __( 'Current price is: %s.', 'woocommerce' ), wp_strip_all_tags( $formatted_sale_price ) ) );
	$price .= '</span>';

	return apply_filters( 'woocommerce_format_sale_price', $price, $regular_price, $sale_price );
}