Artbasement Posted October 2, 2008 Share Posted October 2, 2008 I am trying to edit some Php code for a form in the checkout of my online shopping cart. In the checkout there is a list of various available delivery options, some of which become "£0.00" as you spend over a certain amount. I would like the user to see "FREE" instead of "£0.00", but if another delivery shows "£7.95" (not free) it will still show the price. I have found the bit of script for the form and have tried various things with {if $sm.shipping_price|price > 1} or {...== 0} and so on, but I can't get it to work. It turns all the amounts in the form to "FREE" or none of them. This what I tried... {if $sm.shipping_price|price < 1} {$sm.method_name|htmlspecialchars} - {$sm.shipping_price|price} {else} {if $sm.shipping_price|price > 1} {$sm.method_name|htmlspecialchars} - FREE {/if} {/if} As I am a complete novice at Php, it's probably very simple, but if you could show me how to do that would be great...the original code looked like this <div class="formLine"> <div class="formSpace"> <select id="select_shipping_method" name="shipping_method"> {foreach from=$shipping_methods item="sm"} <option value="{$sm.ssid}" {if $sm.checked == "yes"}selected="selected"{assign var="current_shipping_amount" value=$sm.shipping_price}{/if} onchange="opcRecalcTotalOnShippingChange()"> {$sm.method_name|htmlspecialchars} {if $ShippingPreCalcEnabled == "YES"} - {$sm.shipping_price|price} {/if} </option> {/foreach} </select> </div> </div> {else} {foreach from=$shipping_methods item="sm"} <input type="hidden" id="select_shipping_method" name="shipping_method" value="{$sm.ssid}"/> <div class="formLine"> <div class="formSpace"> <b>Shipping price for your order is {$sm.shipping_price|price}</b><br/> <i>({$sm.method_name|htmlspecialchars}{if $order->shippingTaxable};{$msg.cart.shipping_taxable} - {$order->shippingTaxDescription}{/if})</i> </div> </div> {/foreach} {/if} {/if} {/if} Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/ Share on other sites More sharing options...
gaza165 Posted October 2, 2008 Share Posted October 2, 2008 how are you displaying the price?? is it as a string or as an integer i.e. string(£0.00) or integer £ + 0.00?? Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/#findComment-655464 Share on other sites More sharing options...
Delight Posted October 2, 2008 Share Posted October 2, 2008 If it's an integer then you could do something like this: if ($price == '0.00') { echo 'Free'; } else { echo '£ '.$price; } Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/#findComment-655482 Share on other sites More sharing options...
KevinM1 Posted October 2, 2008 Share Posted October 2, 2008 Well, one of the things masking the problem is the use of a 3rd party template engine to insert PHP code within the markup. There's nothing wrong with using one, but it does make it harder for someone that doesn't use one (like me ) to figure out what's going on. My two compatriots are correct in the structure of how to check the price, assuming it's a number and not a string. if($price > 0) { echo "£" . $price; } else { echo "FREE"; } You should double-check that you're referencing the price(s) correctly. Try outputting it to the screen as is. Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/#findComment-655510 Share on other sites More sharing options...
Artbasement Posted October 2, 2008 Author Share Posted October 2, 2008 I have checked the db and it says "shipping_price" is a "decimel(20,5)" but if I take the "|price" off "$sm.shipping_price|price" it displays "£0.00" as "0". Does that help me? Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/#findComment-655615 Share on other sites More sharing options...
Artbasement Posted October 2, 2008 Author Share Posted October 2, 2008 Did this...and it works! {foreach from=$shipping_methods item="sm"} <option value="{$sm.ssid}" {if $sm.checked == "yes"}selected="selected"{assign var="current_shipping_amount" value=$sm.shipping_price}{/if} onchange="opcRecalcTotalOnShippingChange()"> {$sm.method_name|htmlspecialchars} {if $ShippingPreCalcEnabled == "YES"} {if $sm.shipping_price == 0} - FREE DELIVERY {else} - {$sm.shipping_price|price} {/if} {/if} </option> Quote Link to comment https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/#findComment-655632 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.