风格化的电子商务价格小数:问题



我正在使用这个片段https://stackoverflow.com/a/66521763/15932569但它也有一些问题。https://prnt.sc/13e8n4s我正在尝试编辑楼层操作。

add_filter( 'formatted_woocommerce_price', 'custom_formatted_woocommerce_price', 10, 5 );
function custom_formatted_woocommerce_price( $formatted_price, $price, $decimal_number, $separator, $thousand_separator ) {
// if the price is float
if ( floor( $price ) != $price ) {
// gets the whole part
$int = floor( $price );
// gets the decimal part as an integer (based on the number of decimals set)
$decimals = substr( $price, 0 , -2 );
// if it is an integer
} else {
$int = $price;
$decimals = '00';
}
// returns the price by separating the integer part from the decimals
$formatted_price = '<span class="int">' . $int . $separator . '</span>' . $decimals ;
return $formatted_price ;
echo number_format($formatted_price, 2, ".", ",");
}

你有什么建议吗?

我做到了。它很管用。

我不是开发人员,所以请在代码行中添加一些内容或警告。

谢谢大家。

add_filter( 'formatted_woocommerce_price', 'custom_formatted_woocommerce_price', 10, 5 );
function custom_formatted_woocommerce_price( $formatted_price, $price, $decimal_number, $separator, $thousand_separator ) {

$int = number_format( intval( $price ), 0, $separator, $thousand_separator );
$decimals = '00';

// returns the price by separating the integer part from the decimals
$formatted_price = '<span class="int">' . $int . $separator . '</span>' . $decimals ;
return $formatted_price;
}

最新更新