LindsayKB
2/2/2022 - 2:56 AM

Add Shipping Message if International Customer Is Detected

$(document).ready(function() {
  //Add the message ahead of time
  $("shipping-component").prepend("<span class='intlMsg' style='display:none;'><p><span style='color:red;'>PLEASE NOTE:</span> As with all international shipments, additional customs charges may apply upon delivery. The customer is solely responsible for these changes and for complying with any other restrictions or regulations in their country.(<a href='LINKGOESHERE'>Learn more</a>)</p></span>");
  setTimeout(function(){
    //Trigger the function that checks the country upon page load
    shippingCountry();
  }
             , 2000);
  $("select[name='country']").change( function() {
    //Trigger the function that checks the country if a change is detected
    console.log("Country change");
    shippingCountry();
  }
                                    );
  function shippingCountry() {
    console.log("Function has been called!");
    //Get shipping country value;
    var countryValue = $("#shipping_country").val();
    console.log(countryValue);
    
    //If country value is not the United States, show shipping message
    if (countryValue != "United States")
    {
      $(".intlMsg").css("display","block");
    }
    else {
      $(".intlMsg").css("display","none");
    }
    console.log($(".intlMsg").html());
  }
}
                 );