I have set up a user profile field called "Testing" though the woocommerce membership panel.
I now want to access this field and its data on the front-end of the website.
I looked up the documentation and the closest function I could find is wc_memberships_get_members_area_sections()
which will list only the name of the sections within the membership dashboard and nothing about the content that it contains.
I also looked in the database and found that the user submitted data is stored in the wp_usermeta
table.
So how do I access this data? I want to add three fields i.e. name, age and picture for the user to fill-in and display them back on the front-end pages when the user is logged-in.
2
Answers
The wordpress function
get_user_meta()
will work to fetch the profile field data.The profile field data is returned as an array and you can use
var_dump()
function to check the returned data.I had a "company_name" profile field so I used the code below to fetch it,
I created a helper function to mimic how Woo Memberships saves the data in the wp_user_meta. Pass in the user ID and the ‘slug’ property with a hyphen as your $meta_key order to access the meta value of a given profile field.
Ex