Emergency

In urgent situations or outages, you can send a text message to our emergency line

Emergency line (text message only)

+45 29 70 15 95

Send a text message with the following information:

  • Your name and webshop
  • A description of the problem

Note: This service is only for critical situations where your webshop is down or has serious problems. For regular support, please use our normal support channels.

How to add the free shipping bar and suggestions to your own theme

The free shipping progress bar and suggestions for products that give free shipping are now built into the standard themes. If you build your own theme, you can show the same with one variable, one method, and a small form, and here is the step-by-step guide.

Reading time: approx. 18 min
How to add the free shipping bar and suggestions to your own theme

"How much more do I need to spend to get free shipping?" Customers ask themselves that question in the cart, and the answer often decides whether one more product goes into the cart or the customer pays for shipping. Store owners have asked for a bar that shows it. It is now built into the standard themes, together with product suggestions that close the gap in one click.

Montana, MontanaB2B, Delaware, DelawareDK, Alaska2, and California have it behind two theme settings. If you build custom themes for customers, your themes do not get it automatically. On the other hand, most of the work is done on the server: Shoporama calculates the distance to free shipping with the same rules as checkout and picks the suggestions. Your theme just has to show them. Here is the guide, step by step.

How to build it into your theme

1. Read the free shipping progress

Everything starts with the variable $free_shipping_progress. It is set on every page of the store, but only use it in the cart and on the delivery step, which are never cached. Other pages can be stored in the shared page cache, for example in themes built on Montana, and then every visitor sees the first visitor's numbers. The examples here are written for Smarty 4. $webshop->getFreeShippingProgress() returns the same as the variable if you need it somewhere the variable is not set. When there is something to show, it is an array with five fields:

  • limit: the free shipping threshold ("Free shipping above") on the delivery country or the selected shipping method, in the country's currency.
  • price: the amount measured against the threshold, calculated as in checkout. Add-ons that are excluded from the threshold do not count, a discount code with "Do not count toward the free shipping threshold" (for example, a gift card) is not deducted, and the value of redeemed points is deducted.
  • remaining: how much the customer has left to reach free shipping. 0 when free shipping is reached.
  • percent: an integer from 0 to 100 for the bar.
  • reached: true when the customer has free shipping, including when it comes from a discount code or the loyalty program.

The variable is null when there is nothing to show: when the cart is empty or only contains add-ons, when there is no threshold on the country or the shipping method, when the shipping method has "Never free shipping", and when a product in the cart has "Never free shipping". So start the component with a null check and the text for the customer. The separators and the currency follow the customer's country, so the numbers also look right in a store that sells in several countries:

<{if $free_shipping_progress}>
    <{$fs = $free_shipping_progress}>
    <{$fs_decimal = $webshop->getDecimalSeparator()}>
    <{$fs_thousand = $webshop->getThousandSeparator()}>
    <{$fs_currency = $webshop->getCurrency()}>

    <{if $fs.reached}>
        <p><{t}>Du har fri fragt<{/t}></p>
    <{else}>
        <{$fs_amount = $fs.remaining|number_format:2:$fs_decimal:$fs_thousand}>
        <p><{t x=$fs_amount y=$fs_currency}>Du mangler {x} {y} for at få fri fragt<{/t}></p>
    <{/if}>
<{/if}>

2. Show the progress bar

percent can be used directly as the width. It is at most 99 until free shipping is reached, so the bar never looks full while the customer still pays for shipping. Place the bar below the text, inside the null check:

<div class="free-shipping__bar" role="progressbar" aria-valuenow="<{$fs.percent}>" aria-valuemin="0" aria-valuemax="100" aria-label="<{t}>Fri fragt<{/t}>">
    <div class="free-shipping__fill" style="width: <{$fs.percent}>%"></div>
</div>

Give it a height and a background in your stylesheet. role="progressbar" and the aria attributes let screen readers announce how far along the customer is.

.free-shipping__bar { height: 8px; border-radius: 4px; background: #e8e8e8; overflow: hidden; }
.free-shipping__fill { height: 100%; border-radius: 4px; background: #111827; transition: width .3s; }

3. Get the suggestions

$webshop->getFreeShippingSuggestions($limit) returns products that give free shipping or bring the customer closer. The default is 3, and you can get up to 12. The method reads the cart itself, so you do not need to pass it anything else, and the list is empty when free shipping is reached. Each item has:

  • product: the product, with the same methods as in the rest of the theme.
  • price: the price of one unit that the customer pays, with the same VAT as the cart, including customer group, country, currency, and any campaign on a single product.
  • reaches: true when the product gives free shipping on its own.
  • attribute and values: the variant attribute and the variants that can be bought. attribute is null when the product has no variants.

Shoporama picks the products in a fixed order: first products that are often bought together with the products in the cart, then the best sellers in the same category, and then the store's best sellers. If none of them gives free shipping on its own, the search continues in the right price range among products in the main category of the products in the cart, and finally across the whole store, including products without sales (only those that give free shipping, cheapest first). Products that give free shipping on their own come first, and products that cost far more than the missing amount are filtered out. Products already in the cart, sold-out products, products with "Never free shipping", add-ons, gift cards, bundles, and products with customer input fields are never included. So you can count on every suggestion being ready to add to the cart directly from the card, and products with variants after a choice in the dropdown. Place the suggestions inside the null check from step 1, because they use $fs.

<{$fs_suggestions = []}>
<{if !$fs.reached}>
    <{$fs_suggestions = $webshop->getFreeShippingSuggestions(3)}>
<{/if}>

<{if $fs_suggestions}>
    <p><{t}>Forslag til fri fragt<{/t}></p>
    <ul>
        <{foreach $fs_suggestions as $fs_item}>
            <{$fs_product = $fs_item.product}>
            <li>
                <a href="<{$fs_product->getRemoteUrl()}>"><{$fs_product->getName()|escape}></a>
                <{$fs_item.price|number_format:2:$fs_decimal:$fs_thousand}> <{$fs_currency|escape}>
                <{if $fs_item.reaches}><span><{t}>Giver fri fragt<{/t}></span><{/if}>
            </li>
        <{/foreach}>
    </ul>
<{/if}>

4. Build the add-to-cart form

Each suggestion is its own small form that posts to /, just like a regular add to cart. It sends product_id, amount, and redirect, so the customer returns to the same step. If the product has variants, you also send attributes[attribute-id] with the value's id. If there is only one variant to choose, send it as a hidden field. Otherwise, show a dropdown with required, so the customer cannot press Add without choosing. Replace the <li> from step 3 with:

<li>
    <form action="/" method="post">
        <input type="hidden" name="product_id" value="<{$fs_product->getProductId()}>">
        <input type="hidden" name="amount" value="1">
        <input type="hidden" name="redirect" value="<{$return|default:'/basket'|escape}>">

        <a href="<{$fs_product->getRemoteUrl()}>"><{$fs_product->getName()|escape}></a>
        <{$fs_item.price|number_format:2:$fs_decimal:$fs_thousand}> <{$fs_currency|escape}>
        <{if $fs_item.reaches}><span><{t}>Giver fri fragt<{/t}></span><{/if}>

        <{if $fs_item.attribute}>
            <{if $fs_item.values|@count == 1}>
                <input type="hidden" name="attributes[<{$fs_item.attribute->getAttributeId()}>]" value="<{$fs_item.values[0]->getAttributeValueId()}>">
            <{else}>
                <select name="attributes[<{$fs_item.attribute->getAttributeId()}>]" required>
                    <option value=""><{t}>Vælg<{/t}> <{$fs_item.attribute->getName()|escape}></option>
                    <{foreach $fs_item.values as $fs_value}>
                        <option value="<{$fs_value->getAttributeValueId()}>"><{$fs_value->getVal()|escape}></option>
                    <{/foreach}>
                </select>
            <{/if}>
        <{/if}>

        <button type="submit" value="1"><{t}>Tilføj<{/t}></button>
    </form>
</li>

values only contains variants that can be bought: those in stock, or all of them if the product allows negative stock. If no variant can be bought, the product is not included in the suggestions at all. You set $return when you include the component (see the next step).

5. Place the component

Combine steps 1 to 4 in a file such as components/free-shipping.html, and include it in the cart (basket.html) and on the delivery step (shipping.html). Those two pages are never cached, so the suggestions can be rendered on the server and always match the customer's cart.

Most importantly, the component must be outside the step's own form. The cart and the delivery step are typically one big <form>, and HTML does not allow forms inside forms. So place the card before or after it:

<{* basket.html: before the cart's <form> *}>
<{include file="components/free-shipping.html" return="/basket"}>

<{* shipping.html: before the step's <form>. The wrapper is always there *}>
<div id="checkout-free-shipping">
    <{include file="components/free-shipping.html" return="/shipping"}>
</div>

The threshold can depend on the shipping method, because a shipping method can have its own "Free shipping above". If your theme reloads the delivery step when the customer picks another shipping method, there is nothing to do. If the theme saves the choice with AJAX, replace the card with the new one from the response. That is why the wrapper is always there, even when the card is empty, so the card can appear when the customer picks a method with a threshold:

// When the customer picks another shipping method: save the choice without moving on
var data = new FormData(form);   // the delivery step's form
data.delete('next');

fetch(window.location.pathname, { method: 'POST', body: data, credentials: 'same-origin' })
    .then(function(response) { return response.text(); })
    .then(function(html) {
        var doc = new DOMParser().parseFromString(html, 'text/html');
        var fresh = doc.getElementById('checkout-free-shipping');
        var current = document.getElementById('checkout-free-shipping');
        if (fresh && current) current.replaceWith(fresh);
    });

If you want to let the store owner turn the bar and the suggestions on and off, use the same keys as Montana and Delaware. Add the fields under fields in the checkout_cart group (create the group if the theme does not have it) in theme_settings.json. Without default, they are off until the store owner turns them on:

{
    "path": "enable_free_shipping_bar",
    "name": "Enable Free Shipping Progress Bar",
    "description": "Shows how much the customer needs to add to get free shipping, in the cart and on the delivery step.",
    "type": "bool"
},
{
    "path": "enable_free_shipping_suggestions",
    "name": "Enable Free Shipping Suggestions",
    "description": "Suggests up to 3 products that can be added to the cart with one click.",
    "type": "bool"
}

Include the component when one of them is turned on, and pass them as parameters. Inside the component, wrap the bar in <{if $show_bar}> and only get suggestions when $show_suggestions is true:

<{if $settings.checkout_cart.enable_free_shipping_bar || $settings.checkout_cart.enable_free_shipping_suggestions}>
    <{include file="components/free-shipping.html" show_bar=$settings.checkout_cart.enable_free_shipping_bar show_suggestions=$settings.checkout_cart.enable_free_shipping_suggestions return="/basket"}>
<{/if}>

6. Avoid the pitfalls

Strictly above. Checkout only gives free shipping when the cart is above the threshold. A cart of exactly 499 DKK with a threshold of 499 DKK pays for shipping, and remaining is 0.01. Never compare price and limit yourself. Use reached and remaining, so the bar always says the same as checkout.

Null check. $free_shipping_progress can be null, even when the cart has products, for example when one of them has "Never free shipping". Check it before you read the fields, and show nothing when it is null.

B2B, incl. and excl. VAT. The threshold is measured on the cart price incl. VAT, just like in checkout, and the same goes for price in the suggestions. If the customer buys without VAT, for example a business customer with a VAT number, $vat is 0, and the amount is measured excl. VAT. If your theme shows prices excl. VAT, only convert what is displayed, and only add "(incl. VAT)" after the missing amount when the customer pays VAT. This is how MontanaB2B does it, slightly simplified:

<{* B2B: the product price excl. VAT for display *}>
<{$fs_price = $fs_item.price}>
<{if $b2b}>
    <{$fs_vat_factor = 1 + ($fs_product->getProductVat() / 100)}>
    <{if $fs_vat_factor > 0}><{$fs_price = $fs_price / $fs_vat_factor}><{/if}>
<{/if}>
<{$fs_price|number_format:2:$fs_decimal:$fs_thousand}> <{$fs_currency|escape}>

<{* The missing amount is incl. VAT, as in checkout. Without VAT ($vat 0), it is measured excl. VAT *}>
<{t x=$fs_amount y=$fs_currency}>Du mangler {x} {y} for at få fri fragt<{/t}><{if $b2b && $vat > 0}> <{t}>(inkl. moms)<{/t}><{/if}>

A separate form for each product. Give each suggestion its own form, and never place the component inside the form of the cart or the delivery step. Otherwise, the button submits the wrong form.

Server-side tracking. When the store uses server-side tracking, the customer used to always follow the setting "When an item is added to the cart send the customer to" and ignore redirect. Now the customer returns to /basket or /shipping when redirect is one of them, with the tracking parameters in the URL. The theme does not need to do anything with them. Other values of redirect work as before.

The older variables. $free_shipping_limit and $free_shipping_price still exist and work as before, but they do not take into account gift cards, redeemed points, products with "Never free shipping", or free shipping from a discount code or the loyalty program. Build new themes on $free_shipping_progress.

Read more

The complete component, all the fields, and the rules are in the developer documentation under Free shipping: bar and suggestions. If you want to see it in a real theme, Montana is the reference. How the store owner turns it on in the standard themes, and how the suggestions are chosen, is described in the support article about the free shipping progress bar and suggestions. If you have questions, write to support@shoporama.dk.

Share this post