Jump to content

Recommended Posts

Hi

 

I have been trying to change the following for my website, so that

when my unit price is "0.00" it will show "call for price" but it don't

seem to work.

 

Base on the codes, the result was it'll show both "0.00" and "call for price"

on my website which is wrong.

 

Would greatly appreciate if anyone can help

 

Thanks in advance

 

priceFormat(0);

 

function priceFormat($price, $dispNull = FALSE){

 

if(is_numeric($price)){

 

global $currencyVars;

 

$price = $price * $currencyVars[0]['value'];

 

return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f", $price).$currencyVars[0]['symbolRight'];

 

} elseif($dispNull == TRUE){

global $currencyVars;

return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f",0.00).$currencyVars[0]['symbolRight'];

 

} else {

 

return "Call For Price";

 

}

 

}

 

Link to comment
https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/
Share on other sites

"0" is numeric. Is this what you're after?

function priceFormat($price, $dispNull = FALSE){
    global $currencyVars;

    if(is_numeric($price) && $price != 0){ 
        $price = $price * $currencyVars[0]['value'];
        return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f", $price).$currencyVars[0]['symbolRight'];

    } elseif($dispNull == TRUE){
        return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f",0.00).$currencyVars[0]['symbolRight'];

    } else {
        return "Call For Price";

    }

}

hi

 

I notice that when the sales price is "0.00" it will also show

"call for price" which i think it should be blank.

 

would appreciate if anyone can help.

 

following are the codes for sales price and price format

 

function salePrice($normPrice, $salePrice){

 

global $config;

 

if($config['saleMode']==1){

 

if($salePrice<$normPrice && $salePrice>0){

 

return $salePrice;

 

} else {

 

return FALSE;

 

}

 

} elseif($config['saleMode']==2) {

 

$saleValue = $normPrice * ((100-$config['salePercentOff'])/100);

 

if($saleValue<$normPrice && $saleValue>0){

return $saleValue;

} else {

return FALSE;

}

 

} else {

return FALSE;

}

}

 

function priceFormat($price, $dispNull = FALSE){

global $currencyVars;

 

if(is_numeric($price) && $price != 0){

 

 

$price = $price * $currencyVars[0]['value'];

 

return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f", $price).$currencyVars[0]['symbolRight'];

 

} elseif($dispNull == TRUE) {

return $currencyVars[0]['symbolLeft'].sprintf("%.".$currencyVars[0]['decimalPlaces']."f", 0.00).$currencyVars[0]['symbolRight'];

 

} else {

 

return "Call For Price";

 

}

 

}

 

Thanks in advance

Never mind, I guess my suggestion doesn't really fix the problem. What are you doing with the global variable outside of the function?

 

In your original post, the variable was inside the is_numeric if test:

 

<?php
//...

if(is_numeric($price)){

global $currencyVars;

//...
?>

 

Does the duplicate label come from having it above the if?

 

<?php
//...

global $currencyVars;
   
if(is_numeric($price) && $price != 0){

//...
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.