If customer selects Canada as shipping country and there's a specific product in cart, checkout should not happen and an error message should generate informing customer of why checkout didn't happen.
following is my code some issue with the if loop it only work once.
this is the video link of issue:
https://easyupload.io/6b4mke
<script>
$(document).ready(function(){
//e.preventDefault();
var json_cart = window.cart_json.line_items;
console.log(json_cart);
const countryId = ["Albania"];
const Recharge_productId = [5241288556706];
for(var i=0; i < json_cart.length; i++){
var product_id = json_cart[i].product_id;
console.log(product_id);
if(product_id == Recharge_productId){
console.log("Say Hello");
$('#checkout_shipping_address_country').on('change', function() {
var id = this.value;
console.log(id);
if(id==countryId){
$("#continue-button").click(function(e) {
alert("this product is ban in your country");
return false;
});
}
else{
return true;
}
});
}
else {
console.log("Say not match");
}
break;
}
});
</script>