woocommerce/assets/js/frontend/geolocation.min.js

1 line
1.3 KiB
JavaScript

jQuery(function(a){var n=!1;var e,o=function(){n&&a('a[href^="'+wc_geolocation_params.home_url+'"]:not(a[href*="v="]), a[href^="/"]:not(a[href*="v="])').each(function(){var e=a(this),o=e.attr("href"),t=o.split("#");o=0<(o=t[0]).indexOf("?")?o+"&v="+n:o+"?v="+n,"undefined"!=typeof t[1]&&null!==t[1]&&(o=o+"#"+t[1]),e.attr("href",o)})},t={url:wc_geolocation_params.wc_ajax_url.toString().replace("%%endpoint%%","get_customer_location"),type:"GET",success:function(e){e.success&&e.data.hash&&e.data.hash!==n&&c(e.data.hash)}},c=function(e){Cookies.set("woocommerce_geo_hash",e,{expires:1/24});var o=0<(o=window.location.toString()).indexOf("?v=")||0<o.indexOf("&v=")?o.replace(/v=[^&]+/,"v="+e):0<o.indexOf("?")?o+"&v="+e:o+"?v="+e;window.location=o};("string"!=typeof(e=Cookies.get("woocommerce_geo_hash"))||!e.length||(n=e,0)||n&&new URLSearchParams(window.location.search).get("v")!==n)&&a.ajax(t),n&&a("form").each(function(){var e=a(this),o=e.attr("method"),t=0<e.find('input[name="v"]').length;o&&"get"===o.toLowerCase()&&!t?e.append('<input type="hidden" name="v" value="'+n+'" />'):(t=e.attr("action"))&&(0<t.indexOf("?")?e.attr("action",t+"&v="+n):e.attr("action",t+"?v="+n))}),o(),a(document.body).on("added_to_cart",function(){o()}),a(document.body).on("woocommerce_append_geo_hashes",function(){o()})});