Shopify themes, liquid, logos, and UX
You can add a shipping rates calculator to your cart page that lets customers estimate their shipping costs before they proceed to the checkout page.
The steps for this tutorial differ depending on whether you are using a sectioned or a non-sectioned theme. A sectioned theme is a newer theme that lets you drag and drop to arrange the layout of your store's pages.
To figure out whether your theme supports sections, go to the theme's Edit code page. If there are files in the Sections directory, you are using a sectioned theme. Non-sectioned themes were released before October 2016, and do not have files in the Sections directory.
If you are using a sectioned theme, then click the Sectioned themes link and follow the instructions. If you are using an older, non-sectioned theme, then click the Non-sectioned themes link and follow the instructions.
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
The shipping rates calculator displays your shipping rates on the cart page of your store. If a customer is logged in, then the calculator uses the customer's default shipping address to estimate shipping rates. The shipping rates calculator works with carrier-calculated rates, manual rates, or a combination of the two.
Keep the following in mind when setting up your shipping calculator:
Note: The shipping calculator only works on the cart page at www.your-shop-url.com/cart. It will not work in a cart drawer or a cart popup. If you are not currently using a cart page, then you can change your cart settings by visiting the theme editor.
vendor.js
. If your theme doesn't have a vendor.js
file, then click theme.js
instead.vendor.js
, paste this code hosted on GitHub. If you are editing theme.js
instead, then paste the same code snippet at the very top of the file.theme.js
. To the very bottom of the file, paste the following code:Shopify.Cart.ShippingCalculator.show( { submitButton: theme.strings.shippingCalcSubmitButton, submitButtonDisabled: theme.strings.shippingCalcSubmitButtonDisabled, customerIsLoggedIn: theme.strings.shippingCalcCustomerIsLoggedIn, moneyFormat: theme.strings.shippingCalcMoneyFormat } );
shipping-calculator
, and click Create snippet:shipping-calculator.liquid
snippet, paste this code hosted on GitHub.cart-template.liquid
. If your theme doesn't have a cart-template.liquid
file, then, in the Templates directory, click cart.liquid
.</form>
tag. On a new line right above the closing </form>
tag, paste the following code:{% render 'shipping-calculator' %}
<script> theme.strings = { shippingCalcSubmitButton: {{ settings.shipping_calculator_submit_button_label | default: 'Calculate shipping' | json }}, shippingCalcSubmitButtonDisabled: {{ settings.shipping_calculator_submit_button_label_disabled | default: 'Calculating...' | json }}, {% if customer %}shippingCalcCustomerIsLoggedIn: true,{% endif %} shippingCalcMoneyFormat: {{ shop.money_with_currency_format | json }} } </script> <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js"></script> <script src="/services/javascripts/countries.js"></script> <script src="{{ 'shopify_common.js' | shopify_asset_url }}" defer="defer"></script>
settings_schema.json
. The file will open in the code editor.]
and after the last curly bracket }
- make sure to include that first comma ,
since you're modifying a JSON data structure:, { "name": "Shipping Rates Calculator", "settings": [ { "type": "select", "id": "shipping_calculator", "label": "Show the shipping calculator?", "options": [ { "value": "Disabled", "label": "No" }, { "value": "Enabled", "label": "Yes" } ], "default": "Enabled" }, { "type": "text", "id": "shipping_calculator_heading", "label": "Heading text", "default": "Get shipping estimates" }, { "type": "text", "id": "shipping_calculator_default_country", "label": "Default country selection", "default": "United States" }, { "type": "paragraph", "content": "If your customer is logged-in, the country in his default shipping address will be selected. If you are not sure about the spelling to use here, refer to the first checkout page." }, { "type": "text", "id": "shipping_calculator_submit_button_label", "label": "Submit button label", "default": "Calculate shipping" }, { "type": "text", "id": "shipping_calculator_submit_button_label_disabled", "label": "Submit button label when calculating", "default": "Calculating..." }, { "type": "paragraph", "content": "Do not forget to include the snippet shipping-calculator in your cart.liquid template where you want the shipping calculator to appear. You can get the snippet here: [shipping-calculator.liquid](https:\/\/github.com\/carolineschnapp\/shipping-calculator\/blob\/master\/shipping-calculator.liquid) ." } ] }
You can now edit the settings for your shipping rates calculator from the theme editor.
Editing the shipping calculator HTML
You can edit the HTML code for your shipping rates calculator to make more advanced customizations.
shipping-calculator.liquid
.Editing the shipping calculator CSS
If you want to change the appearance of your shipping rates calculator, then you can add some CSS to your theme stylesheet.
theme.scss.liquid
.Depending on your theme and currency settings, you might see your shipping calculator price estimates displayed on the cart page with un-rendered HTML tags:
To remove these unwanted tags, you will need to make a change to your currency settings in the admin.
Your shipping calculator price estimates should now display without un-rendered HTML tags:
This demo shop has a shipping rates calculator on the cart page.
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
The shipping rates calculator displays your shipping rates on the cart page of your store. If a customer is logged in, then the calculator uses the customer's default shipping address to estimate shipping rates. The shipping rates calculator works with carrier-calculated rates, manual rates, or a combination of the two.
Keep the following in mind when setting up your shipping calculator:
Note: The shipping calculator only works on the cart page at www.your-shop-url.com/cart. It will not work in a cart drawer or a cart popup. If you are not currently using a cart page, then you can change your cart settings by visiting the theme editor.
There are five main steps to install the shipping rates calculator in your theme:
jquery.cart.min
as the name and select .js
as the file extension. Click Add asset.jquery.cart.min
asset, paste this JavaScript code snippet.settings_schema.json
. The file will open in the code editor.]
and after the last curly bracket }
- make sure to include that first comma ,
since you're modifying a JSON data structure:,
{
"name": "Shipping Rates Calculator",
"settings": [
{
"type": "select",
"id": "shipping_calculator",
"label": "Show the shipping calculator?",
"options": [
{
"value": "Disabled",
"label": "No"
},
{
"value": "Enabled",
"label": "Yes"
}
],
"default": "Enabled"
},
{
"type": "text",
"id": "shipping_calculator_heading",
"label": "Heading text",
"default": "Get shipping estimates"
},
{
"type": "text",
"id": "shipping_calculator_default_country",
"label": "Default country selection",
"default": "United States"
},
{
"type": "paragraph",
"content": "If your customer is logged-in, the country in his default shipping address will be selected. If you are not sure about the spelling to use here, refer to the first checkout page."
},
{
"type": "text",
"id": "shipping_calculator_submit_button_label",
"label": "Submit button label",
"default": "Calculate shipping"
},
{
"type": "text",
"id": "shipping_calculator_submit_button_label_disabled",
"label": "Submit button label when calculating",
"default": "Calculating..."
},
{
"type": "paragraph",
"content": "Do not forget to include the snippet shipping-calculator in your cart.liquid
template where you want the shipping calculator to appear. You can get the snippet here: [shipping-calculator.liquid](https:\/\/github.com\/carolineschnapp\/shipping-calculator\/blob\/master\/shipping-calculator.liquid) ." } ] }
shipping-calculator
as the name for your new snippet, then click Create snippet:shipping-calculator
snippet, paste this Liquid code snippet.Include your snippet in your cart.liquid
file in the place where you want to show your shipping rates calculator. In this example, the calculator is right below the cart form on the cart page.
cart.liquid
.</form>
tag. On a new line below the tag, paste the following code:{% render 'shipping-calculator' %}
You can now edit the settings for your shipping rates calculator from the theme editor.
Editing the shipping calculator HTML
You can edit the HTML code for your shipping rates calculator to make more advanced customizations.
shipping-calculator.liquid
.Editing the shipping calculator CSS
If you want to change the appearance of your shipping rates calculator, then you can add some CSS to your theme stylesheet.
theme.scss.liquid
.Updating older themes to use a supported version of jQuery
If you are having trouble getting the shipping calculator to work, then check to confirm that your theme is using a jQuery version of 1.7 or newer. If your theme is running a version of jQuery that is older than 1.7, then you can edit your theme code to use a supported version instead.
theme.liquid
.<head>
element, find a script tag that references your theme's jQuery source. The src
attribute for the script tag contains a URL that includes /jquery/
, followed by the version number. The tag looks something like this:<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>In the script tag above, the jQuery version being used is 1.4.2. This is an older version of jQuery that will need to be updated for the customization to work. If your theme is using a version that is older than 1.7, replace the version number in the URL with 1.7. The result should look like this:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
Demo store
This demo shop has a shipping rates calculator on the cart page.
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hello! I have fixed the shipping calculater, but there is no country selection and i cant try the calculating....how do i get this sorted? Best regards, JRL
I've trying to add the Shipping Calculator to the 'Supply' theme (stock version 9.2 - no customisation other than the Cart 'Page' option chosen rather than 'modal')
On pressing the button it displays "Rates start at $1.00." and in chrome dev/tools I see I have the following error:
cart:1208 Uncaught ReferenceError: theme is not defined
at cart:1208
<script>
theme.strings = {
shippingCalcSubmitButton: "Calculate shipping",
shippingCalcSubmitButtonDisabled: "Calculating...",
shippingCalcMoneyFormat: "\u003cspan class=money\u003e\u003cspan class=money\u003e\u0026pound;{{amount}} GBP\u003c\/span\u003e\u003c\/span\u003e"
}
</script>
I see other posts that have been successful with 'Supply' theme - so I guess I made a mistake somewhere.
And other posts with the same problem as I'm having - but no solution posted.
Guidance needed please
ref above post..
That is the only error on the cart page, but just noticed on the home page I get the following errors:
vendor.js?v=2190683173320769027:70 Uncaught TypeError: Shopify.CountryProvinceSelector is not a constructor
at _init (vendor.js?v=2190683173320769027:70)
at HTMLDocument.<anonymous> (vendor.js?v=2190683173320769027:70)
at i (jquery-2.2.3.min.js?v=5821186314690718683:2)
at Object.fireWith [as resolveWith] (jquery-2.2.3.min.js?v=5821186314690718683:2)
at Function.ready (jquery-2.2.3.min.js?v=5821186314690718683:2)
at HTMLDocument.J (jquery-2.2.3.min.js?v=5821186314690718683:2)
_init @ vendor.js?v=2190683173320769027:70
(anonymous) @ vendor.js?v=2190683173320769027:70
i @ jquery-2.2.3.min.js?v=5821186314690718683:2
fireWith @ jquery-2.2.3.min.js?v=5821186314690718683:2
ready @ jquery-2.2.3.min.js?v=5821186314690718683:2
J @ jquery-2.2.3.min.js?v=5821186314690718683:2
And just a reminder that this is the latest version of Supply unaltered.
It would be really nice if this worked for Cart type/drawer.
Has anyone achieved this?
Refiz o processo duas vezes e não consegui faze-la funcionar, não entendo porque, quando clico no botão de calcular, ela não faz nada, nem mesmo mostra que está "calculando", estou usando o tema DEBUT, tentarei criar outro tema para fazer novamente para ver se foi algo que fiz errado, mas segui o passo a passo corretamente.
Hi Ty,
I have been able to add the calculator to my cart but it doesn't do anything when the Calculate Shipping button is clicked. Any way you can help me figure out what is going on?
Thanks!
I just set this up for a client and followed the guide, he is on an older theme without the vendor.js and the button did not work either (javascript not firing correctly).
What I did to solve it. Instead of adding both of those javscript snippets/code into the top & bottom of the theme.js (or vendor.js) I added them to the very bottom of my theme.liquid right before the closing </body> tag.
Here is what I added:
{% if template contains 'cart' %} <script> /** * Module to add a shipping rates calculator to cart page. * * Copyright (c) 2011-2016 Caroline Schnapp (11heavens.com) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * Modified by David Little, 2016 */ "object"==typeof Countries&&(Countries.updateProvinceLabel=function(e,t){if("string"==typeof e&&Countries[e]&&Countries[e].provinces){if("object"!=typeof t&&(t=document.getElementById("address_province_label"),null===t))return;t.innerHTML=Countries[e].label;var r=jQuery(t).parent();r.find("select");r.find(".custom-style-select-box-inner").html(Countries[e].provinces[0])}}),"undefined"==typeof Shopify.Cart&&(Shopify.Cart={}),Shopify.Cart.ShippingCalculator=function(){var _config={submitButton:"Calculate shipping",submitButtonDisabled:"Calculating...",templateId:"shipping-calculator-response-template",wrapperId:"wrapper-response",customerIsLoggedIn:!1,moneyFormat:"${{amount}}"},_render=function(e){var t=jQuery("#"+_config.templateId),r=jQuery("#"+_config.wrapperId);if(t.length&&r.length){var templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var n=Handlebars.compile(jQuery.trim(t.text())),a=n(e);if(jQuery(a).appendTo(r),"undefined"!=typeof Currency&&"function"==typeof Currency.convertAll){var i="";jQuery("[name=currencies]").size()?i=jQuery("[name=currencies]").val():jQuery("#currencies span.selected").size()&&(i=jQuery("#currencies span.selected").attr("data-currency")),""!==i&&Currency.convertAll(shopCurrency,i,"#wrapper-response span.money, #estimated-shipping span.money")}}},_enableButtons=function(){jQuery(".get-rates").removeAttr("disabled").removeClass("disabled").val(_config.submitButton)},_disableButtons=function(){jQuery(".get-rates").val(_config.submitButtonDisabled).attr("disabled","disabled").addClass("disabled")},_getCartShippingRatesForDestination=function(e){var t={type:"POST",url:"/cart/prepare_shipping_rates",data:jQuery.param({shipping_address:e}),success:_pollForCartShippingRatesForDestination(e),error:_onError};jQuery.ajax(t)},_pollForCartShippingRatesForDestination=function(e){var t=function(){jQuery.ajax("/cart/async_shipping_rates",{dataType:"json",success:function(r,n,a){200===a.status?_onCartShippingRatesUpdate(r.shipping_rates,e):setTimeout(t,500)},error:_onError})};return t},_fullMessagesFromErrors=function(e){var t=[];return jQuery.each(e,function(e,r){jQuery.each(r,function(r,n){t.push(e+" "+n)})}),t},_onError=function(XMLHttpRequest,textStatus){jQuery("#estimated-shipping").hide(),jQuery("#estimated-shipping em").empty(),_enableButtons();var feedback="",data=eval("("+XMLHttpRequest.responseText+")");feedback=data.message?data.message+"("+data.status+"): "+data.description:"Error : "+_fullMessagesFromErrors(data).join("; ")+".","Error : country is not supported."===feedback&&(feedback="We do not ship to this destination."),_render({rates:[],errorFeedback:feedback,success:!1}),jQuery("#"+_config.wrapperId).show()},_onCartShippingRatesUpdate=function(e,t){_enableButtons();var r="";if(t.zip&&(r+=t.zip+", "),t.province&&(r+=t.province+", "),r+=t.country,e.length){"0.00"==e[0].price?jQuery("#estimated-shipping em").html("FREE"):jQuery("#estimated-shipping em").html(_formatRate(e[0].price));for(var n=0;n<e.length;n++)e[n].price=_formatRate(e[n].price)}_render({rates:e,address:r,success:!0}),jQuery("#"+_config.wrapperId+", #estimated-shipping").fadeIn()},_formatRate=function(e){function t(e,t){return"undefined"==typeof e?t:e}function r(e,r,n,a){if(r=t(r,2),n=t(n,","),a=t(a,"."),isNaN(e)||null==e)return 0;e=(e/100).toFixed(r);var i=e.split("."),o=i[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+n),s=i[1]?a+i[1]:"";return o+s}if("function"==typeof Shopify.formatMoney)return Shopify.formatMoney(e,_config.moneyFormat);"string"==typeof e&&(e=e.replace(".",""));var n="",a=/\{\{\s*(\w+)\s*\}\}/,i=_config.moneyFormat;switch(i.match(a)[1]){case"amount":n=r(e,2);break;case"amount_no_decimals":n=r(e,0);break;case"amount_with_comma_separator":n=r(e,2,".",",");break;case"amount_no_decimals_with_comma_separator":n=r(e,0,".",",")}return i.replace(a,n)};return _init=function(){new Shopify.CountryProvinceSelector("address_country","address_province",{hideElement:"address_province_container"});var e=jQuery("#address_country"),t=jQuery("#address_province_label").get(0);"undefined"!=typeof Countries&&(Countries.updateProvinceLabel(e.val(),t),e.change(function(){Countries.updateProvinceLabel(e.val(),t)})),jQuery(".get-rates").click(function(){_disableButtons(),jQuery("#"+_config.wrapperId).empty().hide();var e={};e.zip=jQuery("#address_zip").val()||"",e.country=jQuery("#address_country").val()||"",e.province=jQuery("#address_province").val()||"",_getCartShippingRatesForDestination(e)}),_config.customerIsLoggedIn&&jQuery(".get-rates:eq(0)").trigger("click")},{show:function(e){e=e||{},jQuery.extend(_config,e),jQuery(function(){_init()})},getConfig:function(){return _config},formatRate:function(e){return _formatRate(e)}}}(); // Shipping Calculator continued Shopify.Cart.ShippingCalculator.show( { submitButton: theme.strings.shippingCalcSubmitButton, submitButtonDisabled: theme.strings.shippingCalcSubmitButtonDisabled, customerIsLoggedIn: theme.strings.shippingCalcCustomerIsLoggedIn, moneyFormat: theme.strings.shippingCalcMoneyFormat } ); </script> {% endif %}
Make sure you remove the code from the vendor.js or the theme.js.
Hi all.
Has anybody had any luck on getting the shipping rates calculator to work with Shopify's Multi-Currency feature?
(I know it says it doesn't work)
We get 1-2 emails per week saying the rates are wrong. It is because the shipping rates calculator puts the current currency symbol next to rates[i].price, but does not carry out any conversion.
<ul id="shipping-rates">
<% for (var i=0; i<rates.length; i++) { %>
<li><%= rates[i].name %> {{ 'cart.shipping_calculator.at' | t }} <%= rates[i].price %></li>
<% } %>
</ul>
Thanks
Andy
In the short-term, I opted to use regex to remove the user currency settings and just output using the store's currency - in my case GBP.
<li><%= rates[i].name %> {{ 'cart.shipping_calculator.at' | t }} £<%= regex.exec(rates[i].price) %> GBP</li>
Would still like to do it properly though!
I can't make this work with multi-currency. Shipping cost is always returned in the shops native current, not in the user's currency. Has anyone found a solution to this?
@Voltage_Matt wrote:I just set this up for a client and followed the guide, he is on an older theme without the vendor.js and the button did not work either (javascript not firing correctly).
What I did to solve it. Instead of adding both of those javscript snippets/code into the top & bottom of the theme.js (or vendor.js) I added them to the very bottom of my theme.liquid right before the closing </body> tag.
Here is what I added:{% if template contains 'cart' %} <script> /** * Module to add a shipping rates calculator to cart page. * * Copyright (c) 2011-2016 Caroline Schnapp (11heavens.com) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * Modified by David Little, 2016 */ "object"==typeof Countries&&(Countries.updateProvinceLabel=function(e,t){if("string"==typeof e&&Countries[e]&&Countries[e].provinces){if("object"!=typeof t&&(t=document.getElementById("address_province_label"),null===t))return;t.innerHTML=Countries[e].label;var r=jQuery(t).parent();r.find("select");r.find(".custom-style-select-box-inner").html(Countries[e].provinces[0])}}),"undefined"==typeof Shopify.Cart&&(Shopify.Cart={}),Shopify.Cart.ShippingCalculator=function(){var _config={submitButton:"Calculate shipping",submitButtonDisabled:"Calculating...",templateId:"shipping-calculator-response-template",wrapperId:"wrapper-response",customerIsLoggedIn:!1,moneyFormat:"${{amount}}"},_render=function(e){var t=jQuery("#"+_config.templateId),r=jQuery("#"+_config.wrapperId);if(t.length&&r.length){var templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var n=Handlebars.compile(jQuery.trim(t.text())),a=n(e);if(jQuery(a).appendTo(r),"undefined"!=typeof Currency&&"function"==typeof Currency.convertAll){var i="";jQuery("[name=currencies]").size()?i=jQuery("[name=currencies]").val():jQuery("#currencies span.selected").size()&&(i=jQuery("#currencies span.selected").attr("data-currency")),""!==i&&Currency.convertAll(shopCurrency,i,"#wrapper-response span.money, #estimated-shipping span.money")}}},_enableButtons=function(){jQuery(".get-rates").removeAttr("disabled").removeClass("disabled").val(_config.submitButton)},_disableButtons=function(){jQuery(".get-rates").val(_config.submitButtonDisabled).attr("disabled","disabled").addClass("disabled")},_getCartShippingRatesForDestination=function(e){var t={type:"POST",url:"/cart/prepare_shipping_rates",data:jQuery.param({shipping_address:e}),success:_pollForCartShippingRatesForDestination(e),error:_onError};jQuery.ajax(t)},_pollForCartShippingRatesForDestination=function(e){var t=function(){jQuery.ajax("/cart/async_shipping_rates",{dataType:"json",success:function(r,n,a){200===a.status?_onCartShippingRatesUpdate(r.shipping_rates,e):setTimeout(t,500)},error:_onError})};return t},_fullMessagesFromErrors=function(e){var t=[];return jQuery.each(e,function(e,r){jQuery.each(r,function(r,n){t.push(e+" "+n)})}),t},_onError=function(XMLHttpRequest,textStatus){jQuery("#estimated-shipping").hide(),jQuery("#estimated-shipping em").empty(),_enableButtons();var feedback="",data=eval("("+XMLHttpRequest.responseText+")");feedback=data.message?data.message+"("+data.status+"): "+data.description:"Error : "+_fullMessagesFromErrors(data).join("; ")+".","Error : country is not supported."===feedback&&(feedback="We do not ship to this destination."),_render({rates:[],errorFeedback:feedback,success:!1}),jQuery("#"+_config.wrapperId).show()},_onCartShippingRatesUpdate=function(e,t){_enableButtons();var r="";if(t.zip&&(r+=t.zip+", "),t.province&&(r+=t.province+", "),r+=t.country,e.length){"0.00"==e[0].price?jQuery("#estimated-shipping em").html("FREE"):jQuery("#estimated-shipping em").html(_formatRate(e[0].price));for(var n=0;n<e.length;n++)e[n].price=_formatRate(e[n].price)}_render({rates:e,address:r,success:!0}),jQuery("#"+_config.wrapperId+", #estimated-shipping").fadeIn()},_formatRate=function(e){function t(e,t){return"undefined"==typeof e?t:e}function r(e,r,n,a){if(r=t(r,2),n=t(n,","),a=t(a,"."),isNaN(e)||null==e)return 0;e=(e/100).toFixed(r);var i=e.split("."),o=i[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+n),s=i[1]?a+i[1]:"";return o+s}if("function"==typeof Shopify.formatMoney)return Shopify.formatMoney(e,_config.moneyFormat);"string"==typeof e&&(e=e.replace(".",""));var n="",a=/\{\{\s*(\w+)\s*\}\}/,i=_config.moneyFormat;switch(i.match(a)[1]){case"amount":n=r(e,2);break;case"amount_no_decimals":n=r(e,0);break;case"amount_with_comma_separator":n=r(e,2,".",",");break;case"amount_no_decimals_with_comma_separator":n=r(e,0,".",",")}return i.replace(a,n)};return _init=function(){new Shopify.CountryProvinceSelector("address_country","address_province",{hideElement:"address_province_container"});var e=jQuery("#address_country"),t=jQuery("#address_province_label").get(0);"undefined"!=typeof Countries&&(Countries.updateProvinceLabel(e.val(),t),e.change(function(){Countries.updateProvinceLabel(e.val(),t)})),jQuery(".get-rates").click(function(){_disableButtons(),jQuery("#"+_config.wrapperId).empty().hide();var e={};e.zip=jQuery("#address_zip").val()||"",e.country=jQuery("#address_country").val()||"",e.province=jQuery("#address_province").val()||"",_getCartShippingRatesForDestination(e)}),_config.customerIsLoggedIn&&jQuery(".get-rates:eq(0)").trigger("click")},{show:function(e){e=e||{},jQuery.extend(_config,e),jQuery(function(){_init()})},getConfig:function(){return _config},formatRate:function(e){return _formatRate(e)}}}(); // Shipping Calculator continued Shopify.Cart.ShippingCalculator.show( { submitButton: theme.strings.shippingCalcSubmitButton, submitButtonDisabled: theme.strings.shippingCalcSubmitButtonDisabled, customerIsLoggedIn: theme.strings.shippingCalcCustomerIsLoggedIn, moneyFormat: theme.strings.shippingCalcMoneyFormat } ); </script> {% endif %}
Make sure you remove the code from the vendor.js or the theme.js.
I will try this as using vendor.js and theme.js I face the same problem ...
the calculator is rendered but button did not display anything...
Lets see
@GoodFy_Brasil wrote:
@Voltage_Matt wrote:I just set this up for a client and followed the guide, he is on an older theme without the vendor.js and the button did not work either (javascript not firing correctly).
What I did to solve it. Instead of adding both of those javscript snippets/code into the top & bottom of the theme.js (or vendor.js) I added them to the very bottom of my theme.liquid right before the closing </body> tag.
Here is what I added:{% if template contains 'cart' %} <script> /** * Module to add a shipping rates calculator to cart page. * * Copyright (c) 2011-2016 Caroline Schnapp (11heavens.com) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * Modified by David Little, 2016 */ "object"==typeof Countries&&(Countries.updateProvinceLabel=function(e,t){if("string"==typeof e&&Countries[e]&&Countries[e].provinces){if("object"!=typeof t&&(t=document.getElementById("address_province_label"),null===t))return;t.innerHTML=Countries[e].label;var r=jQuery(t).parent();r.find("select");r.find(".custom-style-select-box-inner").html(Countries[e].provinces[0])}}),"undefined"==typeof Shopify.Cart&&(Shopify.Cart={}),Shopify.Cart.ShippingCalculator=function(){var _config={submitButton:"Calculate shipping",submitButtonDisabled:"Calculating...",templateId:"shipping-calculator-response-template",wrapperId:"wrapper-response",customerIsLoggedIn:!1,moneyFormat:"${{amount}}"},_render=function(e){var t=jQuery("#"+_config.templateId),r=jQuery("#"+_config.wrapperId);if(t.length&&r.length){var templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var n=Handlebars.compile(jQuery.trim(t.text())),a=n(e);if(jQuery(a).appendTo(r),"undefined"!=typeof Currency&&"function"==typeof Currency.convertAll){var i="";jQuery("[name=currencies]").size()?i=jQuery("[name=currencies]").val():jQuery("#currencies span.selected").size()&&(i=jQuery("#currencies span.selected").attr("data-currency")),""!==i&&Currency.convertAll(shopCurrency,i,"#wrapper-response span.money, #estimated-shipping span.money")}}},_enableButtons=function(){jQuery(".get-rates").removeAttr("disabled").removeClass("disabled").val(_config.submitButton)},_disableButtons=function(){jQuery(".get-rates").val(_config.submitButtonDisabled).attr("disabled","disabled").addClass("disabled")},_getCartShippingRatesForDestination=function(e){var t={type:"POST",url:"/cart/prepare_shipping_rates",data:jQuery.param({shipping_address:e}),success:_pollForCartShippingRatesForDestination(e),error:_onError};jQuery.ajax(t)},_pollForCartShippingRatesForDestination=function(e){var t=function(){jQuery.ajax("/cart/async_shipping_rates",{dataType:"json",success:function(r,n,a){200===a.status?_onCartShippingRatesUpdate(r.shipping_rates,e):setTimeout(t,500)},error:_onError})};return t},_fullMessagesFromErrors=function(e){var t=[];return jQuery.each(e,function(e,r){jQuery.each(r,function(r,n){t.push(e+" "+n)})}),t},_onError=function(XMLHttpRequest,textStatus){jQuery("#estimated-shipping").hide(),jQuery("#estimated-shipping em").empty(),_enableButtons();var feedback="",data=eval("("+XMLHttpRequest.responseText+")");feedback=data.message?data.message+"("+data.status+"): "+data.description:"Error : "+_fullMessagesFromErrors(data).join("; ")+".","Error : country is not supported."===feedback&&(feedback="We do not ship to this destination."),_render({rates:[],errorFeedback:feedback,success:!1}),jQuery("#"+_config.wrapperId).show()},_onCartShippingRatesUpdate=function(e,t){_enableButtons();var r="";if(t.zip&&(r+=t.zip+", "),t.province&&(r+=t.province+", "),r+=t.country,e.length){"0.00"==e[0].price?jQuery("#estimated-shipping em").html("FREE"):jQuery("#estimated-shipping em").html(_formatRate(e[0].price));for(var n=0;n<e.length;n++)e[n].price=_formatRate(e[n].price)}_render({rates:e,address:r,success:!0}),jQuery("#"+_config.wrapperId+", #estimated-shipping").fadeIn()},_formatRate=function(e){function t(e,t){return"undefined"==typeof e?t:e}function r(e,r,n,a){if(r=t(r,2),n=t(n,","),a=t(a,"."),isNaN(e)||null==e)return 0;e=(e/100).toFixed(r);var i=e.split("."),o=i[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+n),s=i[1]?a+i[1]:"";return o+s}if("function"==typeof Shopify.formatMoney)return Shopify.formatMoney(e,_config.moneyFormat);"string"==typeof e&&(e=e.replace(".",""));var n="",a=/\{\{\s*(\w+)\s*\}\}/,i=_config.moneyFormat;switch(i.match(a)[1]){case"amount":n=r(e,2);break;case"amount_no_decimals":n=r(e,0);break;case"amount_with_comma_separator":n=r(e,2,".",",");break;case"amount_no_decimals_with_comma_separator":n=r(e,0,".",",")}return i.replace(a,n)};return _init=function(){new Shopify.CountryProvinceSelector("address_country","address_province",{hideElement:"address_province_container"});var e=jQuery("#address_country"),t=jQuery("#address_province_label").get(0);"undefined"!=typeof Countries&&(Countries.updateProvinceLabel(e.val(),t),e.change(function(){Countries.updateProvinceLabel(e.val(),t)})),jQuery(".get-rates").click(function(){_disableButtons(),jQuery("#"+_config.wrapperId).empty().hide();var e={};e.zip=jQuery("#address_zip").val()||"",e.country=jQuery("#address_country").val()||"",e.province=jQuery("#address_province").val()||"",_getCartShippingRatesForDestination(e)}),_config.customerIsLoggedIn&&jQuery(".get-rates:eq(0)").trigger("click")},{show:function(e){e=e||{},jQuery.extend(_config,e),jQuery(function(){_init()})},getConfig:function(){return _config},formatRate:function(e){return _formatRate(e)}}}(); // Shipping Calculator continued Shopify.Cart.ShippingCalculator.show( { submitButton: theme.strings.shippingCalcSubmitButton, submitButtonDisabled: theme.strings.shippingCalcSubmitButtonDisabled, customerIsLoggedIn: theme.strings.shippingCalcCustomerIsLoggedIn, moneyFormat: theme.strings.shippingCalcMoneyFormat } ); </script> {% endif %}
Make sure you remove the code from the vendor.js or the theme.js.
I will try this as using vendor.js and theme.js I face the same problem ...
the calculator is rendered but button did not display anything...
Lets see
Not working for a NON Shopify Theme ... still need to check why ... as for FREE SHOPIFY THEME has worked
Hi There,
Do you know where to modify the code so that it picks up the suburb as well? I am using BESPOKE SHIPPING to calculate live rates and as the live rates also depend on the suburb, the shipping calculator does not calculate the live rates.
Hi,
I´m using Narrative theme and the calculater appears, looks pretty good but does not calculate anything. It seems that it doesn do anything, not even an error message. Does anybody know, what the problem could be? Does anybody tried it with Narrative theme?
Second question: Is it possible to have only the country-field and leave the zip-field? We configered our shipping costs equal for all regions in a country.
Even after I've made those changes, my button doesn't even shows "calculating...". It just doesn't work.
What can I do?
It says that it needs underscore.js to work, does it have something to do with it? can I install it in my template?
EDIT: It shows the following error:
Uncaught ReferenceError: theme is not defined
at cart:596
(anonymous) @ cart:596
I tried adding the snippets in vendor.js and theme.js with no result, then tried this and got it working!!!!. I'm using Boundless theme
@kabobmaster wrote:Hi Ty,
I have been able to add the calculator to my cart but it doesn't do anything when the Calculate Shipping button is clicked. Any way you can help me figure out what is going on?
Thanks!
Hey @kabobmaster did you solve this ? I just followed the instructions and has worked perfectly ... let us know what did you get and what Theme are you using
I have not been able to solve this. I am currently using Shopify's Debut theme. I had a Shopify expert help me but they did not get it working. All they did was place all of the github code in the cart-template.liquid
When the button is pressed, it displays "Calculating..." but returns without results and the button text reads "Calculate Shipping" again.
Also it might be helpful to note that I am using a shipping calculator app called Intuitive Shipping. I was also using Advanced Shipping Rules prior and with both shipping apps the calculator would not work.
@kabobmaster wrote:I have not been able to solve this. I am currently using Shopify's Debut theme. I had a Shopify expert help me but they did not get it working. All they did was place all of the github code in the cart-template.liquid
When the button is pressed, it displays "Calculating..." but returns without results and the button text reads "Calculate Shipping" again.
Also it might be helpful to note that I am using a shipping calculator app called Intuitive Shipping. I was also using Advanced Shipping Rules prior and with both shipping apps the calculator would not work.
Ok ... I will try this in DEBUT Theme ...
If you watn you can share me an admin staff account so I can take a look in your store .
My email is william@beautylet.com.br
Best Regards
@GoodFy_Brasil wrote:
@kabobmaster wrote:I have not been able to solve this. I am currently using Shopify's Debut theme. I had a Shopify expert help me but they did not get it working. All they did was place all of the github code in the cart-template.liquid
When the button is pressed, it displays "Calculating..." but returns without results and the button text reads "Calculate Shipping" again.
Also it might be helpful to note that I am using a shipping calculator app called Intuitive Shipping. I was also using Advanced Shipping Rules prior and with both shipping apps the calculator would not work.
Ok ... I will try this in DEBUT Theme ...
If you watn you can share me an admin staff account so I can take a look in your store .
My email is william@beautylet.com.br
Best Regards
I found my problem. My theme was still on Debut V1. I had to port all my customizations to a new Debut theme and things worked.
I followed the "Updating older themes to use a supported version of jQuery" and it works for me. If the first one does not work. Try to change it to the second one. I really do not have an idea what jquery version do I have
Thank you for posting this, I found it very easy to implement and it was a great enhancement to my cart at:
However, after months of working really well, it suddenly stopped for no reason and only the following text was appearing:
"Rates start at £13.00 GBP."
I followed the instructions again, overwriting the existing code, and now have:
"Rates start at £13.00 GBP.
Rates start at £13.00 GBP."
I wonder if Shopify have made any changes that would have stopped this working?
I'm really missing it 😞
Thanks again,
Sarah
Hey Sarah,
Did you find any solution of this issue? I'm facing the same issue. Please let me know if you have any solution.
Thanks
Please delete
Thanks for this! I've set it up on an older non-sectioned theme and it works great!
However, I have a problem on a sectioned theme.
I get this error: "Uncaught ReferenceError: theme is not defined" for this code:
<script> theme.strings = { shippingCalcSubmitButton: "Calculate shipping", shippingCalcSubmitButtonDisabled: "Calculating...", shippingCalcMoneyFormat: "\u003cspan class=money\u003e${{amount}} USD\u003c\/span\u003e" } </script>
Any suggestions to fix this?
Várias tags com erro, não deu para concluir o processo....
Does anyone know if we can configure this calculator to display the shipping prices we set from our settings?
Our current shipping settings are:
1 Pair of socks = $5 shipping
2-3 Pairs = Free Shipping
4+ Pairs = Free Express shipping
Please help.
Thanks
I set up my shop but I can't make it "live" as I want shoppers to know what the shipping is before they purchase. I followed all the instructions but it didn't work. Is there any support to help integrate this?
I doesn't make sense to have the postage rates after you put in your bank details. In my opinion that will just put people off.
I did it again and it's working!
No idea why it shows 2 results though.
I was able to get this working, we use the Supply Theme. A couple problems we identified was on the Home Page, the "Collection List" became distorted and blocked the Title partially, and the Mobile Menu didn't work while using a smart phone (Android). Wasn't sure if anybody else had this issue?
delete please
I don't know how to just reply to the whole post as opposed to someone else's reply post but just wanted to say,
I tried this on simple theme a while back and could not get it to work. I now tried it with supply theme and it works perfectly. ( I even changed the position of where it rendered and the css) There were so many good questions and answers here Thank you everyone!
Did you ever get a fix for this?
Mine is doing the same thing
Troubleshooting
Depending on your theme and currency settings, you might see your shipping calculator price estimates displayed on the cart page with un-rendered HTML tags:
To remove these unwanted tags, you will need to make a change to your currency settings in the admin.
- From your Shopify admin, go to Settings > General.
- In the Store currency section, your shop currency is listed. Click Change formatting.
- Remove the HTML tags from your currency formats. By default, the settings look like this:
From both the HTML with currency and the HTML without currency text fields, remove the opening and closing HTML span tags. The result should look like this:- Click Save.
Your shipping calculator price estimates should now display without un-rendered HTML tags:
Do NOT change your store's currency settings as described here as this will break any currency selector you might have installed in your store.
Make sure to keep your store's currency settings WITH the span class tags, like this example:
HTML with currency: <span class=money>${{amount}} USD</span>
HTML without currency: <span class=money>${{amount}}</span>
To fix the issue where the span class appears in the shipping calculator rates estimates, go into the shipping-calulator.liquid snippet you made earlier and find {{price}} (with double curly braces), and change that to {{{price}}} (with triple curly braces).
@TyW wrote:Troubleshooting
Depending on your theme and currency settings, you might see your shipping calculator price estimates displayed on the cart page with un-rendered HTML tags:
To remove these unwanted tags, you will need to make a change to your currency settings in the admin.
- From your Shopify admin, go to Settings > General.
- In the Store currency section, your shop currency is listed. Click Change formatting.
- Remove the HTML tags from your currency formats. By default, the settings look like this:
From both the HTML with currency and the HTML without currency text fields, remove the opening and closing HTML span tags. The result should look like this:- Click Save.
Your shipping calculator price estimates should now display without un-rendered HTML tags:
Do NOT change your currency settings as described here in the "Sectioned Themes" post, as this will break any currency selector you might have installed in your store.
Make sure to keep your store's currency settings WITH the span class tags, like this example:
HTML with currency: <span class=money>${{amount}} USD</span>
HTML without currency: <span class=money>${{amount}}</span>
To fix the issue where the span class appears in the shipping calculator rates estimates, go into the shipping-calculator.liquid snippet you made earlier and find {{price}} (with double curly braces). Change that to {{{price}}} (with triple curly braces). ( In Handlebars, which this script uses for this part, {{price}} is HTML-escaped, but {{{price}}} is not.)
Do NOT change your currency settings as described in the "Sectioned Themes" post, as this will break any currency selector you might have installed in your store.
Make sure to keep your store's currency settings WITH the span class tags, like this example:
HTML with currency: <span class=money>${{amount}} USD</span>
HTML without currency: <span class=money>${{amount}}</span>
To fix the issue where the span class appears in the shipping calculator rates estimates:
Go into the shipping-calculator.liquid snippet you made earlier and find {{price}} (with double curly braces).
Change that to {{{price}}} (with triple curly braces).
(In Handlebars, which this snippet uses, {{price}} will be HTML-escaped, but {{{price}}} will not.)
This is great. Followed your steps and it works. Thanks for positing.
Is there are way to show all shipping option.?
Also, any suggestion on how we can add a tax estimate as well?
Thanks, Diego
You can do this to display shipping method and the rate. I don't know how to do the taxes.
Modify the response in the shipping-calculator.liquid
{{#if success}} {{#if rates}} {{#rates}} {{#if @first}} <br/> Available rates are: <br/><br/> {{/if}} {{name}}: {{price}} <br/> {{/rates}} {{else}} We do not ship to this destination. {{/if}} {{else}} {{ errorFeedback }} {{/if}}
Thanks.
Thanks for sharing this piece of code, it's a great improvement to the implementation. So there is the possibility to show all forms of shipping and not just the price. For Brazil, it works perfectly!
What did you mean by 'all forms of shipping'?? Is it relevant to this discussion?
Hello @chenster.
In Brazil we work with many delivery methods. What I meant is that it displays all possible shipping forms for the address entered, for example:
And so on, this way it lists all the shipping options and not just the value that starts the shipping, because if I offer a free shipping, it will show that the shipping starts at a value of 0.
@DabsDesign wrote:Hello @chenster.
In Brazil we work with many delivery methods. What I meant is that it displays all possible shipping forms for the address entered, for example:
- delivery by car - "estimated price"
- delivery by boat - "estimatede price"
- delivery by airplane - "estimatede price"
And so on, this way it lists all the shipping options and not just the value that starts the shipping, because if I offer a free shipping, it will show that the shipping starts at a value of 0.
This app (not mine) offers estimate by delivery type. I'm not sure it can do exactly 100% what you need. Give it a try.
https://apps.shopify.com/shipping-based-on-zipcode
@kabobmaster or @chenster how i change the currency. Actually is showing $ but I need to change to R$, the default currency for Brazil.
I using this code:
<script id="shipping-calculator-response-template" type="text/template">
{% raw %}
<p id="shipping-rates-feedback" {{#if success}} class="success" {{else}} class="error" {{/if}}>
{{#if success}}
{{#if rates}}
{{#rates}}
{{#if @first}}
<br/>
<span style="font-size: 16px; color: #9a0fee;">
Os fretes disponíveis são:
</span>
<br/>
{{/if}}
{{name}}: {{price}}
<br/>
{{/rates}}
{{else}}
Não foi possível realizar o calculo do frete. Tente novamente.
{{/if}}
{{else}}
{{ errorFeedback }}
{{/if}}
</p>
{% endraw %}
</script>
I change the currency in this place or another? Any help (from anyone) is welcome!
You can check out https://www.techonthenet.com/js/number_tolocalestring.php for symbol display
@chenster can you be more specific, please. Like teach what I need to do? 😉
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024