Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
v:2.0:snippets:dynamically_require_phone [2018/07/28 07:44] – [Add Javascript] adamv:2.0:snippets:dynamically_require_phone [2018/07/30 06:02] (current) adam
Line 7: Line 7:
 Copy and paste the following code into your store's custom "footer" option. This can be found on the "configuration" page of your store's FoxyCart administration, look for the option labelled "Add custom header and footer code to your templates". Enable it if it isn't already, and paste the code into the "footer" textarea of that option. Copy and paste the following code into your store's custom "footer" option. This can be found on the "configuration" page of your store's FoxyCart administration, look for the option labelled "Add custom header and footer code to your templates". Enable it if it isn't already, and paste the code into the "footer" textarea of that option.
  
-<code javascript>{% if context == "checkout" %}<script type="text/javascript">+<code javascript>{% if context == "checkout" %} 
 +<script type="text/javascript">
 function requirePhone(params) { function requirePhone(params) {
     var country = params.address.country;     var country = params.address.country;
Line 14: Line 15:
         FC.json.required_fields.push('billing_phone');         FC.json.required_fields.push('billing_phone');
         FC.json.config.template_config.custom_checkout_field_requirements['billing_phone'] = "required";         FC.json.config.template_config.custom_checkout_field_requirements['billing_phone'] = "required";
 +        FC.Template("checkout").clearOutput();
         FC.checkout.renderCustomerShipping();         FC.checkout.renderCustomerShipping();
     } else if (country == "US" && phone_required > -1) {     } else if (country == "US" && phone_required > -1) {
Line 20: Line 22:
         FC.util.removeError(params.address.prefix + "_phone");         FC.util.removeError(params.address.prefix + "_phone");
         FC.util.notifyErrors();         FC.util.notifyErrors();
 +        FC.Template("checkout").clearOutput();
         FC.checkout.renderCustomerShipping();         FC.checkout.renderCustomerShipping();
     }     }
 } }
 + 
 FC.client.on("customer-address-change", requirePhone); FC.client.on("customer-address-change", requirePhone);
 FC.client.on("ready.done", function() { FC.client.on("ready.done", function() {
Line 37: Line 40:
     }     }
 }); });
-</script>{% endif %}</code>+</script> 
 +{% endif %}</code>

Site Tools