Add custom meta field to registration

Add custom meta field to registration

snoopus
Visitor
3 0 0

Hey there,

 

so I added a custom meta field for accounts, where namespace and key is "custom.question1".

Now I added the following code to my main-register.liquid:

 

 

<select
  name="customer[custom.question1]"
  id="RegisterForm-customQuestion1"
  required
>
  <option value="" disabled>Please choose</option>
  <option>Answer1</option>
  <option>Answer2</option>
  <option>Answer3</option>
</select>

 

 

But that doesn't work. I guess the name property "customer[custom.question1]" is the problem. What do I have to enter in the name attribute so that it gets saved to the created meta field? I already tried "customer[question1]" and "customer[custom][question1]".

 

Thanks in advance!

Replies 5 (5)

BSSCommerce-TA
Shopify Partner
123 24 24

Hi @snoopus , you can get the value of metafields in liquid like this

 

<select
    name="{{ customer.metafields.custom.question1 }}"
    id="RegisterForm-customQuestion1"
    required
  >
    <option value="" disabled>Please choose</option>
    <option>Answer1</option>
    <option>Answer2</option>
    <option>Answer3</option>
 </select>

 

Hope this will help you ❤️

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.

SIMICART: Mobile App Builder |Ironwork Theme - Coming Soon | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
snoopus
Visitor
3 0 0

@BSSCommerce-TA Thanks for your reply! I copied the code but it still doesn't work, unfortunately. In the form's source code the name attribute is empty. But no error is shown on submit. But in the shopify backend under customers the field will be empty. I also tried to use a simple input instead of a select. Didn't work either.

 

Maybe the following screenshots help (although they're in German).

 

Bildschirmfoto 2024-06-24 um 16.48.59.png

Bildschirmfoto 2024-06-24 um 16.49.19.png

  

Bildschirmfoto 2024-06-24 um 16.50.37.png

Bildschirmfoto 2024-06-24 um 16.51.47.png

BSSCommerce-TA
Shopify Partner
123 24 24

Hi @snoopus , you should use metaobjects instead of metafields, because customer metafields only exist if a user logged in.

Here is the step to add metaobjects:
1. Go to "Content" section in your admin store, then select metaobjects

2. Add definition and save

 

BSSCommerceTA_1-1719280057175.png

3. Then go to Content => Metaobjects again

Select your definition and add entry

BSSCommerceTA_2-1719280121467.png

BSSCommerceTA_3-1719280174945.png

4. Then you can access metaobjects every where in your themes like this:

 

 

<select
    name="{{ shop.metaobjects['form_question']['question-1'].question_name }}"
    placeholder="{{ shop.metaobjects['form_question']['question-1'].question_content }}"
    id="RegisterForm-customQuestion1"
    required
  >
    <option value="" disabled>Please choose</option>
    <option>Answer1</option>
    <option>Answer2</option>
    <option>Answer3</option>
 </select>

 

 

 

Note: "question-1" is your entry handle, you can get it after create an entry

BSSCommerceTA_4-1719280604178.png

"form_question" is your metaobjects type

BSSCommerceTA_0-1719284391979.png

 

 

The result will be like this:

BSSCommerceTA_5-1719280732190.png

Hope this will help you

 

 

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.

SIMICART: Mobile App Builder |Ironwork Theme - Coming Soon | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency

Brett_Helium
Shopify Partner
238 45 102

Hey @snoopus!

 

Unfortunately it is actually not possible to save values directly into customer metafields directly through Liquid, this has to be done through the APIs (with an app). That's why we built the Customer Fields app, a no-code solution to allow merchants to build custom registration forms, and easily save all of your custom data directly into Shopify's customer metafields.

Brett | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (350+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (280+ reviews)
snoopus
Visitor
3 0 0

@Brett_Helium Thanks for your reply. I was afraid of that. Generally, I don't mind creating my own app, but I'm not really sure how I could hook into the registration process. With other tools (e.g., WordPress), I'm used to having extensive tutorials/documentation available, but with Shopify, it seems that the majority of users don't have coding skills, so all the helpful resources are behind a paywall. Which is great for them, but not for devs like me.

 

I read elsewhere that you build your own form for this purpose, is that correct? And then, upon submitting the form, there is presumably some registration endpoint that can be called via JavaScript/PHP/Anything?