I want to restrict people attending my event based on their zipcode

Question:
How would I go about or is it even possible to not allow people from zip codes outside of my town to use my services?

Product:
Wix editor

What are you trying to achieve:
I need to automatically allow customers from several zip codes in my area to book services but customers outside of that zone to be put on a waitlist or denied access to booking services.

What have you already tried:
I have only tried searching to internet for solutions

export async function chkIpAddress() {
    try {
        const httpResponse = await fetch('https://extreme-ip-lookup.com/json', {
            method: 'get'
        });

        if (httpResponse.ok) {
            const json = await httpResponse.json();
            const ipaddress = json.query;
            const country = json.country;
            const city = json.city;
            return { "ipaddress": ipaddress, "country": country, "city": city };
        } else {
            throw new Error('Failed to fetch IP information');
        }
    } catch (error) {
        console.error('Error fetching IP information:', error);
        return null; // or handle the error in an appropriate way for your application
    }
}

Expanding the function to get our ZIP-CODES…

export async function chkIpAddress() {
    try {
        const ipResponse = await fetch('https://extreme-ip-lookup.com/json', {
            method: 'get'
        });

        if (ipResponse.ok) {
            const ipJson = await ipResponse.json();
            const ipaddress = ipJson.query;
            const country = ipJson.country;
            const city = ipJson.city;

            // Use the IP address in your application
            console.log('User IP Address:', ipaddress);

            // Fetch additional details including ZIP code using IPinfo API
            const ipinfoResponse = await fetch(`https://ipinfo.io/${ipaddress}/json`);
            if (ipinfoResponse.ok) {
                const ipinfoJson = await ipinfoResponse.json();
                const zipCode = ipinfoJson.postal;
                console.log('User ZIP Code:', zipCode);

                return { "ipaddress": ipaddress, "country": country, "city": city, "zipCode": zipCode };
            } else {
                throw new Error('Failed to fetch ZIP code information');
            }
        } else {
            throw new Error('Failed to fetch IP information');
        }
    } catch (error) {
        console.error('Error fetching IP information:', error);
        return null; // or handle the error in an appropriate way for your application
    }
}

You also could use the Wix-Window-API…

You will have to modify the presented code to get it to work (just an example).

Similar posts from the past…

Hello @Shariff_Harris, Yes, you can restrict bookings based on ZIP codes using Wix Velo. Below is the code-supported solution for the user to apply this feature by using Wix Velo code -

import { local } from 'wix-storage';

const allowedZips = ["10001", "10002", "90210", "30301"]; // Replace with your ZIP codes

$w.onReady(() => {

$w("#bookingBox").hide();

$w("#submitBtn").onClick(() => {

const enteredZip = $w("#zipInput").value.trim();

if (!enteredZip) {

$w("#zipResultText").text = "Please enter your ZIP code.";

return;

}

if (allowedZips.includes(enteredZip)) {

$w("#zipResultText").text = "You're eligible to book!";

$w("#bookingBox").show();

local.setItem("userZip", enteredZip); // optional: store for later use

} else {

$w("#zipResultText").text = "Sorry, bookings are currently limited to select areas. You’ve been added to our waitlist!";

$w("#bookingBox").hide();

}

});

});

If you’d rather avoid custom code and just upload a ZIP list, we’ve built a ZipCode Checker & Validator app for Wix. It supports CSV ZIP uploads, so no need for putting data manually. Shows a custom message for eligible/ineligible users. It can be used for any page you want.

Hope this helps you get things running smoothly! Let me know if you need help adapting this for your site.