В Интернете есть множество решений, к сожалению, ни одно из них не работает эффективно.
Это самое близкое, что мне удалось заставить это работать:
Код: Выделить всё
add_filter( 'formatted_woocommerce_price', 'dcwd_superscript_wc_formatted_price', 10, 5 );
function dcwd_superscript_wc_formatted_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
// Leave prices unchanged in Dashboard.
if ( is_admin() ) {
return $formatted_price;
}
// Format units, including thousands separator if necessary.
$unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
// Format decimals, with leading zeros as necessary (e.g. for 2 decimals, 0 becomes 00, 3 becomes 03 etc).
$decimal = '';
$num_decimals = wc_get_price_decimals();
if ( $num_decimals ) {
$decimal = sprintf( '%0'.$num_decimals.'d', round( ( $price - intval( $price ) ) * 100 ) );
}
return $unit . '' . $decimal_separator. $decimal . '';
}
// Remove decimals if .00
add_filter( 'formatted_woocommerce_price', 'dcwd_remove_zero_decimals', 10, 5 );
function dcwd_remove_zero_decimals( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
/*
// Leave decimals in on single product page.
if ( is_product() ) {
return $formatted_price;
}
*/
if ( $price - intval( $price ) == 0 ) {
// Format units, including thousands separator if necessary.
return $unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
}
else {
return $formatted_price;
}
}
Кто-нибудь еще предложит лучший или другой способ добиться этого?
Заранее благодарю за внимание и советы.
Подробнее здесь: https://stackoverflow.com/questions/786 ... hide-if-00