<?php
add_action( 'facetwp_scripts', function() {
?>
<script>
(function($) {
// Store original alert
var originalAlert = window.alert;
// Override window.alert
window.alert = function(msg) {
// Catch all FacetWP geolocation alerts
if (
msg === "User denied the request for Geolocation." ||
msg === "Location information is unavailable." ||
msg === "The request to get user location timed out." ||
msg === "An unknown error occurred."
) {
// Suppress FacetWP's original alert, do nothing here
return;
}
// Otherwise, let other alerts work as normal
originalAlert(msg);
};
// Now show custom messages via the FacetWP error hook
FWP.hooks.addAction('facetwp/geolocation/error', function(obj) {
let error = obj.error;
let customMessage = "We couldn’t detect your location. Please allow location access.";
switch (error.code) {
case error.PERMISSION_DENIED:
customMessage = "⚠️ You blocked location sharing. Please enable it in your browser.";
break;
case error.POSITION_UNAVAILABLE:
customMessage = "📡 Location info is not available right now.";
break;
case error.TIMEOUT:
customMessage = "⏳ The request took too long. Please try again.";
break;
case error.UNKNOWN_ERROR:
customMessage = "❌ An unknown error occurred while getting your location.";
break;
}
originalAlert(customMessage); // Show thecustom alert
});
})(fUtil);
</script>
<?php
}, 100 );