I need a custom code that would automatically block all orders made with the same phone number for COD orders, as well as block all orders that are made with a phone number present on a blacklist of phone numbers
Hi @il.terra.paolo Welcome to the community!
Great question—and yes, this kind of custom validation is possible with a bit of JavaScript in your Funnelish checkout.
Here’s the general approach you can take:
Goal:
- Block duplicate COD orders using the same phone number
- Block orders with phone numbers on a blacklist
How to Implement:
You can use a custom script that:
- Detects the phone number entered
- Checks it against a local blacklist (or remote DB if available)
- Prevents form submission if it’s a match
Here’s a basic snippet to get you started:
<script>
const blacklistedPhones = ['+1234567890', '+1987654321']; // Add your blacklisted numbers here
document.addEventListener('DOMContentLoaded', function () {
const phoneInput = document.querySelector('input[name="phone"]');
if (phoneInput) {
phoneInput.addEventListener('input', () => {
phoneInput.setCustomValidity('');
});
document.querySelector('form').addEventListener('submit', function (e) {
const phone = phoneInput.value.trim();
// Example: Check if it's blacklisted
if (blacklistedPhones.includes(phone)) {
e.preventDefault();
phoneInput.setCustomValidity('This phone number is blocked.');
phoneInput.reportValidity();
return;
}
// Example: Check localStorage for repeat phone (for demo only — not secure)
if (localStorage.getItem(`cod_${phone}`)) {
e.preventDefault();
phoneInput.setCustomValidity('Duplicate COD order detected.');
phoneInput.reportValidity();
return;
}
// Save to localStorage as a simple client-side flag (optional)
localStorage.setItem(`cod_${phone}`, 'true');
});
}
});
</script>
Note: This is a basic client-side solution. For a more secure and scalable approach (like checking a server-side database of past orders), you’d want to integrate this logic via a backend endpoint or webhook.
If you let me know more about how your blacklist is stored (static or dynamic), I can help tailor this further to your setup.
Happy to help you get this running smoothly!
Best,
Anwer