Feature

I need a feature like below for add to cart button in wix store

To hide the add to cart button if a user has already purchased the product linked with it, you can use the getMember() function in the page’s onReady() function to retrieve the ID of the current user viewing the page. Then query() the Stores/Orders collection and filter by the buyerInfo field using the member ID. This will return orders on your store made by that user.

If any of the orders contain that product, then hide() the “add to cart” button and show() the other one


import { currentMember } from 'wix-members';
import wixData from 'wix-data';

$w.onReady(function () {
    const options = {
        fieldsets : ['FULL']
    }
    currentMember.getMember(options)
    .then((member)=>{
        const id  = member._id;
        const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
        return member;
    })
    .catch((error)=>{
        console.error(error);
    });

    wixData.query("Stores/Orders")
    .eq("id","buyerInfo")
    .find()
    .then((results)=>{
        if(results.items.length>0){
            let firstItem = results.items[0];
            if(firstItem === "Solar Skill Development"){
                $w('#addToCartButton3').hide();
            }
            else 
            {
             $w('#addToCartButton3').show();
            }
        }else
        {
            //
        }

        
    })
    .catch((error)=>{
        console.error(error);
    });

});