I’d like to create a custom member property that would store if user had opt-in or not to a beta test program. Is there a way to do this?
I can’t figure out how to store data by member with databases. For information, I am using the regular member area for simplicity.
Hi!
Members Area comes with Members Collection that stores all registered users (_id, email, firstName, lastName)
You can’t create and update data from Members Collection. Only read.
When would you like to receive this Custom Property from User?
1 If during registration, that I suggest you to use Custom Signup Form or Custom Corvid Form
Note: Collected information from Custom Signup will be stored in CRM Collection. You can get this info using method crm.getContactById(currentUser.id)
2 If after registration, that I suggest you to store information in you own User collection , that you can create and setup as you wish.
It would be after registration. I’d like them to be able to change a switch a button on the member area to opt-in. Then, if opted-in, the switch should be activated and user should be able to switch it off. Can you see what I need? It looks like a newsletter subscription checkbox.
Is there a way to synchronize the Members Collection with my own User collection as you mention ?
@benp With Members Area you can’t add optional property and then change it on Members “My Account” Page
You can create your own “My Account” page with custom design and fields.
Users Collection will be store value of your Custom Property per User Email. It means, that you can get user email and query Users Collection to get Custom Property and do what you want.
When you need to write data with Custom Property to Users Collection?
It depends on you
So, I do:
When user go to “My Account” page I check for his email in Users Collection. If no data, then I create it with default data, it data exists I just use it and update if needed.
That’s all I can advise
@illiao Thanks for the help. I created the following code.
It works well on on computer but do not work on mobile, any ideas?
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
var userEmail;
var aplusstatus;
var mbplusstatus;
$w.onReady(async function(){
var user = wixUsers.currentUser;
await user.getEmail()
.then( (email) => {
userEmail = email; // “user@something.com”
});
As I understand you must use wixData.get(“UserCustom”, userEmail) instead wixData.get(“UserCustom”, “example@example.com”)
I don’t recommend use async function as callback in $w.onReady().
Best practice is to make async function main() and call it inside
$w.onReady(function () { main() })
I am not a coder at all that’s why I was expecting bad practices to come up Sorry if it hurts coder eyes !
Could you please tell me how to return the userEmail value and share the variable with the 2 other functions ? Without async/await, it returns “undefined” when I call the variable userEmail outside the getEmail function.