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

1 line
1.2 KiB
JavaScript

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