less than a minute read • Updated 21 days ago
Change the terms of service link by location
How to show a different terms of service link at checkout depending on the customer's selected country or state, using custom JavaScript — useful for region-specific legal requirements.
The following functionality allows you to customize the terms of service link based on the states or countries selected by the user.
Add JavaScript
Paste the following into the "footer" textarea of the "Add custom header and footer code to your templates" option, found on the "configuration" page in your store's Foxy administration.
{% if context == "checkout" %}
<script>
function setTermsLink() {
//Billing or Shipping Region or Country?
//var string_to_check = FC.json.shipping_address.country;
//var string_to_check = FC.json.billing_address.region;
var string_to_check = FC.json.shipping_address.region;
switch (string_to_check) {
case "ID":
url = "http://link-id.com";
break;
case "WA":
url = "http://link-wa.com";
break;
default:
url = "http://link-default.com";
}
FC.json.config.template_config.tos_checkbox_settings.url = url;
FC.Template("checkout").clearOutput();
FC.checkout.renderAdditionalFields();
}
FC.client.on("customer-address-change.done", setTermsLink);
FC.client.on("ready.done", setTermsLink);
</script>