Jump to content

Recommended Posts

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}

Link to comment
https://forums.phpfreaks.com/topic/126726-how-to-change-%C2%A3000-in-to-free/
Share on other sites

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 :D ) 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.

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>

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.