Мне нужно отобразить десятичную единицу измерения.
Поэтому я отделил десятичную часть, используя следующий код.
/>
Но это выглядит так (единица измерения указана рядом с ценой):

Подскажите, пожалуйста, как поставить десятичную единицу измерения, вот так?

Отображается HTML-код интерфейса:
Код: Выделить всё
$285
ea
Код: Выделить всё
add_filter( 'formatted_woocommerce_price', 'ts_woo_decimal_price', 10, 5 );
function ts_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
$unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
$decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 );
return $unit . '' . $decimal . '';
}
Код: Выделить всё
public function wc_uom_render_output( $price ) {
global $post;
// Check if uom text exists.
$woo_uom_output = get_post_meta( $post->ID, '_woo_uom_input', true );
// Check if variable OR UOM text exists.
if ( $woo_uom_output ) :
$price = $price . ' ' . esc_attr( $woo_uom_output, 'woocommerce-uom' ) . '';
return $price;
else :
return $price;
endif;
}
Подробнее здесь: https://stackoverflow.com/questions/699 ... erce-price