...
In the header of the view cart or single page checkout screen branding you can use the following code snippet. This code uses the catalog Velocity code to perform some simple math calculations and display the appropriate message to the customer.
Code Block | ||
---|---|---|
| ||
#set ($freeThreshold = $formatHelper.parseBigDecimal("100"))
#if ($cart.getSubTotalAsBigDecimal() < $freeThreshold)
#set ($neededUntilFree = $freeThreshold.subtract($cart.getSubTotalAsBigDecimal()))
You will receive free shipping if you spend $${neededUntilFree} more.<br/>
#end
|
First navigate to the screen branding by clicking:
Panel |
---|
Main Menu ConfigurationScreen Branding ThemesEditScreensView → Configuration → Screen Branding Themes → Edit → Screens → View Cart edit |
Inside of the view cart header paste the snippet into the header as shown below.
...
Let's take some time to digest what exactly this code is doing. Below is the first line of the code.
Code Block | ||
---|---|---|
| ||
#set ($freeThreshold = $formatHelper.parseBigDecimal("100"))
|
This line basically takes the value of 100 and converts it into a numeric object known as a BigDecimal for comparison later. If you wanted to change the threshold of free shipping for this calculation just change the 100 to something else. Make sure that you leave the quotes around the value. Now on to the next line of code.
Code Block | ||
---|---|---|
| ||
#if ($cart.getSubTotalAsBigDecimal() < $freeThreshold)
|
This line simply compares the subtotal of the cart to the threshold. We don't want to display a message to the customer if they've already cleared the required amount. The line of code below will now calculate the difference that they need to add to their cart to receive the free shipping.
Code Block | ||
---|---|---|
| ||
#set ($neededUntilFree = $freeThreshold.subtract($cart.getSubTotalAsBigDecimal()))
|
We are performing a simple subtraction calculation and assigning the value to a variable. Finally we print the actual message to the customer.
Code Block | ||
---|---|---|
| ||
You will receive free shipping if you spend $${neededUntilFree} more.<br/>
|
...