jtis Posted May 3, 2012 Share Posted May 3, 2012 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"; } } Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/ Share on other sites More sharing options...
Barand Posted May 3, 2012 Share Posted May 3, 2012 "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"; } } Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1342585 Share on other sites More sharing options...
jtis Posted May 3, 2012 Author Share Posted May 3, 2012 Hi Thanks, had tried updating and uploaded the scripts. and the result is "call for price" appear twice. attached herewith the result for your reference. Thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1342615 Share on other sites More sharing options...
jtis Posted May 8, 2012 Author Share Posted May 8, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1343882 Share on other sites More sharing options...
cyberRobot Posted May 8, 2012 Share Posted May 8, 2012 Assuming that you don't want negative pricing, you could change the code to: <?php //... if(is_numeric($price) && $price > 0) { //... ?> Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1343944 Share on other sites More sharing options...
jtis Posted May 8, 2012 Author Share Posted May 8, 2012 hi thanks but the result is still the same it still show "call for price" twice when the retail price is "0.00" it should show "call for price" when the sales price is "0.00" it should be blank appreciate if you could help. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1343948 Share on other sites More sharing options...
cyberRobot Posted May 8, 2012 Share Posted May 8, 2012 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){ //... ?> Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1343949 Share on other sites More sharing options...
jtis Posted May 8, 2012 Author Share Posted May 8, 2012 hi had tried both ways, the result is still the same Quote Link to comment https://forums.phpfreaks.com/topic/261990-setting-price-value-to-text/#findComment-1343954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.