How can I get the cart's shipping address in the cart.liquid file?

笑着哭i 提交于 2019-12-13 03:51:36

问题


I'm trying to change the tax and shipping method prompt based on the user's current shipping address. Obviously, they are not yet at checkout so have not had the opportunity to input their shipping address. Is there anything else I can check at this stage to find out which country they are from?

{% if shipping_address.country_code = 'CA' %}
    <p class="cart-message meta">INCLUDING TAX AND SHIPPING (U.S. AND CANADA)</p>
{% else %}
    <p class="cart-message meta">{{ 'cart.general.tax_and_shipping' | t }} (INTERNATIONAL)</p>
{% endif %}

回答1:


Shipping address at cart.liquid can only be accessed if visitor have already logged in. Else you can use third party tool to show a particular div specific to a particular country.

<script>
var txt = httpGet("https://ipapi.co/json/");
var obj = JSON.parse(txt);
var country = obj.country;

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}
if(country == "CA"){
    // Show Div
}else{
  // Show Other Div
}        

</script>

Note: IP is used to find location of visitor.



来源:https://stackoverflow.com/questions/54565745/how-can-i-get-the-carts-shipping-address-in-the-cart-liquid-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!