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…