Quick Tip: hide shipping cost for non registered users

In this quick tip, we will see how to hide the shipping cost, or misleading free shipping label for non-registered customers.

Watch The Screencast (text below)

 

Hide shipping cost for non registered users

You might have come across this issue if you setup zones so that carriers have a different price depending on the customer’s address: a default shipping price, or even worse a free shipping label is shown for everybody who has not login yet.

This can be misleading at times, and some of your customers will definitely get angry if the price rises after adding shipping address details. Moreover, we do not want this.

First, let’s disable our carrier (remember to do it for all carriers if you use many) for visitors in the back office. Go to Shipping -> Carriers and click on a carrier. Then, disable it for visitors.

Disable carrier for visitors

You can also do it for guests if you disabled the guest checkout.

Refresh and see it says free shipping! This is even more misleading but now we can target that label and still have the total match the products total price.

Let’s go to modules/blockcart and copy blockcart.tpl in the theme folder modules/blockcart. Open it and locate the second script block:


<script type="text/javascript">
var customizationIdMessage = '{l s='Customization #' mod='blockcart' js=1}';
var removingLinkText = '{l s='Please remove this product from my cart.' mod='blockcart' js=1}';
var freeShippingTranslation = '{l s='Free shipping!' mod='blockcart' js=1}';
var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}';
var delete_txt = '{l s='Delete' mod='blockcart' js=1}';
</script>

See where it reads free shipping? We need to change the block as follows


<script type="text/javascript">
var customizationIdMessage = '{l s='Customization #' mod='blockcart' js=1}';
var removingLinkText = '{l s='Please remove this product from my cart.' mod='blockcart' js=1}';

var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}';
var delete_txt = '{l s='Delete' mod='blockcart' js=1}';

//<![CDATA[[

	{if !$logged AND !$cart->id_customer}
		var freeShippingTranslation = '{l s='Login to see the shipping cost!' mod='blockcart' js=1}';		
	{else}
		var freeShippingTranslation = '{l s='Free shipping!' mod='blockcart' js=1}';
	{/if}

//]]>
</script>

As you can see, we removed the free shipping text and added it below. We used a small trick to target the unregistered customer. So, If the customer is not logged in, nor has added any shipping information (that is, no customer id exists for him), then show a different text. Else, it is okay to display the free shipping label.

It looks a bit ugly now, because the cart block is still displaying the shipping label. Let’s hide that as well! Locate the following at about line 154 of the same file:

<span>{l s='Shipping' mod='blockcart'}</span>

And change it the following way

{if $logged OR $cart->id_customer}
	<span>{l s='Shipping' mod='blockcart'}</span>
{/if}	

This time, the text will only be shown if the customer is logged or has already added shipping information.

As a finishing touch, we can add the little information to shopping cart.tpl as well (you can find it in the theme folder once again). Locate this:


<tr class="cart_total_delivery" style="{if !isset($carrier->id) || is_null($carrier->id)}display:none;{/if}">
	<td colspan="5">{l s='Shipping'}</td>
	<td colspan="2" class="price" id="total_shipping">{l s='Free Shipping!'}</td>
</tr>


And change it this way

<tr class="cart_total_delivery">
	<td colspan="5">{l s='Shipping'}</td>
	<td colspan="2" class="price" id="total_shipping">
		
		{if !$logged AND !$cart->id_customer}
			{l s='Login for the correct price'}
		{else}
			{l s='Free Shipping!'}
		{/if}
		

	</td>
</tr>

Note that other than adding the same condition as before, we also removed the display:none style. There is a little downside to this, as that block will always be shown, even if there are no carriers available for the destination. However, this won’t happen if you setup zones, countries and states the correct way.

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

  • Nope

    This does not work. Checking off those boxes does not hide from unregistered users.

  • sara

    Thanks!!
    What if I need to translate it? I could just do it in the files we just modifyed. But I plan to have the website in 2 or 3 languages later. Then it will be a porblem to hardcode the translation..
    //Sara

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: