All Collections
Frequently Asked Questions (FAQ)
Website touchpoints
How can I encourage visitors to spend €50 or more for free shipping?
How can I encourage visitors to spend €50 or more for free shipping?
Xander Wijering avatar
Written by Xander Wijering
Updated over a week ago

Question: I want to encourage visitors to my website to spend €50 or more for free shipping. How can I use a Field Function to calculate the amount they still need to spend and optionally format it in a suitable price format?

Solution: To address this issue, you can follow the steps below:

Step 1: Create a Field Function

Go to your Datatrics project and create a new Field Function with a descriptive name, for example, "calculateAmountForFreeShipping."

Step 2: Define the Field Function

Define the Field Function in the code editor using JavaScript. Here is an example of the code:

if (data.shopping_cart_value !== undefined) {
var amountNeededForFreeShipping = 50 - data.shopping_cart_value;

// Rounding to 2 decimal places
var roundedAmount = Math.round(amountNeededForFreeShipping * 100) / 100;

// Formatting in the European price format (with a comma)
var formattedAmount = roundedAmount.toFixed(2).replace('.', ',');

output(formattedAmount);
} else {
output(null);
}

And name it: calculateAmountForFreeShipping.

This code calculates the amount still required to spend €50 or more for free shipping. It rounds this amount to 2 decimal places and formats it.

Step 3: Use the Field Function in Your Template

Now, you can use the Field Function in your template to display the calculated amount. Make sure to pass shopping_cart_value as an argument to the Field Function, as shown in the following example:

<div class="our-class">Still € {{#fieldfunction calculateAmountForFreeShipping shopping_cart_value=shopping_cart_value}}</div>

This will correctly calculate and display the amount needed for free shipping in the desired format, such as "You still need to add € 0,05 for free shipping".

Note: use targeting like shopping cart < 50 in your touchpoint to prevent showing a case like You still need to add € -20,85 for free shipping".

With this Field Function, you can implement an attractive way to encourage your visitors to spend more for free shipping while ensuring that the amount is correctly rounded and displayed in the correct price format.

Did this answer your question?