Automatically block orders made with same phone number for COD orders

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 :wave: 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:

:white_check_mark: Goal:

  • Block duplicate COD orders using the same phone number
  • Block orders with phone numbers on a blacklist

:hammer_and_wrench: How to Implement:

You can use a custom script that:

  1. Detects the phone number entered
  2. Checks it against a local blacklist (or remote DB if available)
  3. 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>

:brain: 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