خرید بک لینک
Hello guys,

First of all I'm really new to WordPress (know a little of code but not web). I'm making a site with an Apptheme's theme called classipress for classifieds. My page let's you post and AD in btc or USD but the problem is that for btc I need several decimals (around 5) and with USD it just doesn't feel good seeing 5 decimal (specially five zeroes)...
I'd like to know if someone could help me with an IF clause since I read some manuals on wordpress and still can't figure out how to make it in this language.

the working code that always shows the 5 decimals is:

function cp_price_format( $price ) {
global $cp_options;

if ( is_numeric( $price ) ) {
$decimals = ( $cp_options->hide_decimals || $price == 0 ) ? 0 : 5;
$decimal_separator = $cp_options->decimal_separator;
$thousands_separator = $cp_options->thousands_separator;

$price = number_format( $price, $decimals, $decimal_separator, $thousands_separator );
}

return $price;
}

If I were to change the return $price for return floatval($price); it will ALWAYS erase the decimals, I need to only erase decimals if they are only zeroes.

I tried doing something like this:

function cp_price_format( $price ) {
global $cp_options;

if ( is_numeric( $price ) ) {
$decimals = ( $cp_options->hide_decimals || $price == 0 ) ? 0 : 5;
$decimal_separator = $cp_options->decimal_separator;
$thousands_separator = $cp_options->thousands_separator;

$price = number_format( $price, $decimals, $decimal_separator, $thousands_separator );
}

if ($decimals ==0){ return floatval($price);}
else {return $price;}
}

But it didn't work at all... I guess its a problem with the {} or the commas, but can't figure it out just starting with wordpress...

I'd really appreciate if someone could do the IF clause for me so I can make it work and learn how to do it propperly.

Thank you very much for taking the time to read this.

برچسب: نویسنده: آیلین رضوانی تاريخ: دوشنبه 25 دی 1396 ساعت: 6:23

صفحه بندی