Blocking specific countries by tag (checkout) & product title (product page)

Below code is taken from team liquid.
product page (pr_form.liquid)
{% assign ptitle = product.title | downcase %}
{% if ptitle contains "marvel" %}
	<script>
    $(document).ready(function() {
        $.get("//ipinfo.io/?token=f2a02c74d816ea", function(response) {
            console.log("ip: "+ response.ip, response.country);

    			$('#shopify_add_to_cart').click(function(e) {
                  //if (window.location.href.indexOf("?variant=30407093223481") > -1 || window.location.href.indexOf("?variant=30407230521401") > -1) {}
                  //else{
                  	var arrayCountries = ["US","CA","AF","AL","DZ","AD","AO","AT","BH","BE","BJ","BM","BA","BW","IO","BG","BF","BI","CM","CV","CF","TD","KM","CG","HR","CY","CZ","DK","DJ","EG","GQ","ER","EE","ET","FI","FR","GA","GM","DE","GH","GI","GR","GL","GP","GN","GW","HU","IS","IQ","IE","IL","IT","CI","JO","KE","KW","LV","LB","LS","LR","LY","LI","LT","LU","MK","MG","MW","ML","MT","MQ","MR","MU","MD","MC","MA","MZ","NA","NL","NE","NG","NO","OM","PL","PT","QA","RE","RO","RW","ST","SM","SA","SN","RS","SC","SL","SK","SI","SO","ZA","ES","SH","SZ","SE","CH","TZ","TG","TN","TR","UG","UA","GB","AE","VA","EH","YE","ZM","ZW","AU","CK","PF","NZ","PN","WS","HK","TW","CN","IN","MM","JP","BR","MX","BN","ID","PH","SG","TH","VN","RU"]
                    if(arrayCountries.indexOf(response.country) > -1){}
                  	else{
                      e.preventDefault();
                      e.stopPropagation();
                      $('#shopify_add_to_cart, #shopify_add_to_cart.bold_clone').prop('disabled', true);
                      $(this).parent().parent().append('<div style="margin-top: 10px;color: red; font-weight: bold;">Sorry, this items belongs to the Liquid x Marvel collection and cannot be shipped to your country: '+response.country+'.</div>');
                    }
                  //}
    			});

        }, "jsonp");
    });
	</script>
{% endif %}

  script editor
def carthasgeneral
  for item in Input.cart.line_items
  if item.variant.product.tags.include? "Generalprofile"
      return true
    end
  end
  return false
end
def carthasmarvel
  for item in Input.cart.line_items
    if item.variant.product.tags.include? "MarvelProfile"
      return true
    end
  end
  return false
end
def carthasnonmarvel
  for item in Input.cart.line_items
    if item.variant.product.tags.include? "NonmarvelMTprofile"
      return true
    end
  end
  return false
end
if carthasgeneral == true && carthasmarvel == true || carthasgeneral == true && carthasnonmarvel == true || carthasmarvel == true && carthasnonmarvel == true
Input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  shipping_rate.apply_discount(shipping_rate.price * 0.30, message: "NOTE: Items will ship from two different locations and arrive separately.")
end
end
Output.shipping_rates = Input.shipping_rates

checkout.liquid
 <script
            src="https://code.jquery.com/jquery-3.4.1.min.js"
            integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
            crossorigin="anonymous"></script>
    <script>
      $(function() {
        const skus_in_cart = [
		{%- if checkout.order_id or checkout.order_number -%}
			  {%- for item in checkout.line_items -%}
                  {{ item.sku | json }},
              {%- endfor -%}
          {%- endif -%}
        ];
        const ok_countries = ["United States", "Canada", "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Austria", "Bahrain", "Belgium", "Benin", "Bermuda", "Bosnia-Herz", "Botswana", "British Indian Ocean Territory", "Bulgaria", "Burkina-Faso", "Burundi", "Cameroon", "Cape Verde", "Central Afr. Rep", "Chad", "Comoros", "Congo", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Egypt", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Finland", "France", "Gabon", "Gambia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Guadeloupe", "Guinea", "Guinea-Bissau", "Hungary", "Iceland", "Iraq", "Ireland", "Israel", "Italy", "Ivory Coast", "Jordan", "Kenya", "Kuwait", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi", "Mali", "Malta", "Martinique", "Mauritania", "Mauritius", "Moldavia", "Monaco", "Morocco", "Mozambique", "Namibia", "Netherlands", "Niger", "Nigeria", "Norway", "Oman", "Poland", "Portugal", "Qatar", "Reunion", "Romania", "Rwanda", "S. Tome Principe", "San Marino", "Saudi Arabia", "Senegal", "Serbia/Montenegro", "Seychelles", "Sierra Leone", "Slovakia", "Slovenia", "Somalia", "South Africa", "Spain", "St. Helena", "Swaziland", "Sweden", "Switzerland", "Tanzania", "Togo", "Tunisia", "Turkey", "Uganda", "Ukraine", "United Kingdom", "United Arab Emirates", "Vatican City", "West Sahara", "Yemen", "Zambia", "Zimbabwe"];
        
        const collection_items = [
          "LIQUID x MARVEL Spider-Man Artwork Tee",
          "LIQUID x MARVEL Spider-Man Artwork Tank",
          "LIQUID x MARVEL Spider-Man Artwork Long Sleeve Tee",
          "LIQUID x MARVEL Spider-Man Artwork Hoodie",
          "LIQUID x MARVEL Spider-Man Artwork Crop Tee",
          "LIQUID x MARVEL Spider-Man Jersey",
          "LIQUID x MARVEL Captain America Jersey",
          "LIQUID x MARVEL Iron Man Jersey",
          "LIQUID x MARVEL Logo Tee",
          "LIQUID x MARVEL Avengers: Endgame Quantum Realm Jersey"
        ];
        
        const collection_match_strings = [
          "LIQUID x MARVEL",
          "Team Liquid x Marvel"
        ];

        $(".section--shipping-address").append("<div id='shipping_err' style='display:none'>Sorry, one or more of the items in your cart belongs to the Liquid x Marvel collection and cannot be shipped to this country.</div>");
        $(".section.section--shipping-method").append("<div id='shipping_err' style='display:none'>Sorry, one or more of the items in your cart belongs to the Liquid x Marvel collection and cannot be shipped to this country.</div>");
        $(".section--shipping-address").append("<div id='shipping_notif' style='display:none'>Please note: Your Liquid x Marvel items will be delivered separately from the rest of your order.</div>");

        var cart_items = $(".product__description__name").map(function() {
            return $.trim($(this).text());
        }).get();

        function is_blocked_country(country) {
            if (!ok_countries.includes(country))
                return true;
            return false;
        }

        function is_in_collection(product) {
            if (collection_items.includes(product))
                return true;
            return false;
        }
        
        function product_matches_collection(product) {
          for (let str of collection_match_strings) {
            if (product.includes (str))
              return true;
          }
        }

        function has_whirlwind_in_cart () {
            for (let i of cart_items) {
              	if (product_matches_collection (i))
                    return true;
                if (is_in_collection(i))
                    return true;
            }
            return false;
        }

        function has_other_in_cart () {
            for (let i of cart_items) {
                if (!is_in_collection(i) && !product_matches_collection(i))
                    return true;
            }
            return false;
        }

        function show_error(country) {
            if (is_blocked_country(country) && has_whirlwind_in_cart()) {
              console.log('country-blocked');
                $("#shipping_err").show();
                $(".step__footer__continue-btn.btn").addClass("btn--disabled");
                $(".step__footer__continue-btn.btn").prop("disabled", true);
            } else if (has_whirlwind_in_cart() && has_other_in_cart()) {
                $("#shipping_err").hide();
                $("#shipping_notif").show();
                $(".step__footer__continue-btn.btn").removeClass("btn--disabled");
                $(".step__footer__continue-btn.btn").prop("disabled", false);
            } else {
              console.log("111");
                $("#shipping_err").hide();
                $(".step__footer__continue-btn.btn").removeClass("btn--disabled");
                $(".step__footer__continue-btn.btn").prop("disabled", false);
            }
        }
        var address_arr = $("address").text().split(",");
         show_error(address_arr[address_arr.length-1].trim());
        $("select#checkout_shipping_address_country.field__input.field__input--select").change(function() {
            show_error($('select#checkout_shipping_address_country.field__input.field__input--select option:selected').text());
        }).change();
      });
    </script>
    <style>
      .shipping-rate__original-price{display:none !important;}.section--shipping-method del{display:none !important;}.section--shipping-method .radio__label__accessory br{display:none !important;}
      span.radio__label__primary span.small-text {
          font-size: 10px;
      }
    </style>