
How to show “spend X to get Free Shipping” in Prestashop
In this Prestashop tutorial, we will see how to boost our sales by letting customers know how much they still have to spend in order to be eligible for free shipping.
Version used: Prestashop 1.6
Setting the Free Shipping amount
To keep thing simple, in this tutorial we will only consider the “Free shipping starts at” value that we can configure in the back office, instead of dealing with all the 0-fee weight or price ranges that it’s possible to setup for each carrier.
Therefore, before starting, head to Shipping -> Preferences and set “Free shipping starts at” to any value you like. Please notice this represent the price in the default currency, and it’s not possible to set up one for each, at the time being.
Retrieving the Free shipping value – 2 approaches
When dealing with an MVC pattern, the best approach is usually to keep logic and display code separated. Prestashop, however, allows us to retrieve the previously set configuration value in templates too, saving us the trouble to create an override and extend the default OrderController, in order to assign the value we need.
Therefore, given that the best way to go would be to create an override, grab the configuration value, and assign it to the template, for simplicity reasons I will get it directly in the template, so it’s ready to use.
Amending the template: shopping-cart.tpl
Reach your theme folder and open up shopping-cart.tpl. We will be adding our small advertisement right below the cart summary. This is the perfect chance to apply some cross-selling principles; therefore, if you use the cross-selling module in the cart page, the best spot to maximize your cross-selling rate is right above it, before the shopping cart hook .
Locate:
<div id="HOOK_SHOPPING_CART">{$HOOK_SHOPPING_CART}</div>
And right before it, add the following
{assign var='freeshipping_price' value=Configuration::get('PS_SHIPPING_FREE_PRICE')}
Explanation: as I mentioned before, I am grabbing the free shipping value directly from the tpl file, and assigning it to a variable that can be used within our Prestashop template.
Then, we need to check if it is actually holding a value
{assign var='freeshipping_price' value=Configuration::get('PS_SHIPPING_FREE_PRICE')} {if $freeshipping_price} {assign var='freeshipping_price_converted' value={toolsConvertPrice price=$freeshipping_price}} {/if}
Explanation: if the value exists, we need to convert it to the current currency (which might be other than the default). Therefore, we use the very handy toolsConvertPrice method to make sure the value is correctly set to the actual customer currency.
What’s next? We need to compare the total cart value without shipping to the free shipping one, and display a message in case it’s positive:
{assign var='freeshipping_price' value=Configuration::get('PS_SHIPPING_FREE_PRICE')} {if $freeshipping_price} {assign var='freeshipping_price_converted' value={toolsConvertPrice price=$freeshipping_price}} {math equation='a-b' a=$total_price b=$total_shipping assign='total_without_shipping'} {math equation='a-b' a=$freeshipping_price_converted b=$total_without_shipping assign='remaining_to_spend'} {if $remaining_to_spend > 0} <p>{l s='Your total (without shipping) is'} {convertPrice price=$total_without_shipping}</p> <p><strong>{l s='You will be eligible for free shipping if you spend another'} {convertPrice price=$remaining_to_spend}</strong></p> {/if} {/if}
Explanation: first, we subtract the total shipping price from the overall total, which is the value taken in consideration by Prestashop when deciding if a cart is eligible or not, and then we simply subtract it from our minimum free shipping threshold. If the result is positive, we tell our customers how much is left to get rid of the shipping charge!