jQuery(document).ready(function($) { var isWide = true; const porkBlocked = ['EU', 'CA', 'UK']; // Example list of country codes // Step 1: Function to get a cookie by name function getCookie(name) { let cookieArray = document.cookie.split(';'); for(let i = 0; i < cookieArray.length; i++) { let cookiePair = cookieArray[i].split('='); if(name == cookiePair[0].trim()) { return decodeURIComponent(cookiePair[1]); } } return null; } function setCookie(name, value, days) { let expires = ""; if (days) { let date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function checkRegionAndDisplayContent() { let region = getCookie('region'); if (!region) { // If region cookie doesn't exist, fetch the user's country code $.getJSON('http://ip-api.com/json/', function(data) { region = data.countryCode; setCookie('userLocalRegion', region, 7); // Set the region cookie for 7 days }).fail(function(error) { console.error('Error fetching the user country code:', error); }); } else { } region = 'CA'; hideOrShowContent(region, porkBlocked); } // Step 4: Function to hide or show content based on the country code function hideOrShowContent(region, porkBlocked) { if (porkBlocked.includes(region)) { // Hide the content if the region is in the porkBlocked list $('.region-shown').hide(); } else { // Show the content otherwise $('.region-shown').show(); } } checkRegionAndDisplayContent(); });