Body: <p>I  am working on a craftcms + commerce project and I need to add a billing address to new user during its registration process. The idea is to have a billing address added to any newly registered user (no shipping address needed, as the shop will deliver no physical product).</p>
  <p>I have been struggling with this and managed to get the user registered and the address record created in the DB with a 2-step form flow (first register user, then add address), but the address does not get linked to the user.</p>
  <p>Is this possible or perhaps I am trying something completely against the way craftcms/commerce works?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-18T07:37:58.873Z
Comments.Text: That should definitely work... are you successfully populating the userId field in the save-user form when saving the address?
Comments.UserDisplayName: James Smith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-18T09:32:08.217Z
Comments.Text: I think I figured out how this works. craftcms/commerce creates a "floating" customer as soon as a guest (not logged user) visits the page. In order to properly add addresses to a user (frontend) it has to be logged in.  
  So the process would be: register user -> activate -> user logs in -> user adds addresses.  
  I am thinking a way would be checking if the user has any registered address in the login form and:  
  - If they  have no addresses, set a redirect to the profile/add address form.  
  - If they already have at least one address, set a redirect to homepage.
Comments.UserDisplayName: juanlopez4691
Tags: <plugin-craftcommerce><users><registration>
Title: Add billing address to user on registration
ThreadText: # Add billing address to user on registration
  
  (Asked by: username_0 on 2020-08-17)
  
  I am working on a craftcms + commerce project and I need to add a billing address to new user during its registration process. The idea is to have a billing address added to any newly registered user (no shipping address needed, as the shop will deliver no physical product).
  
  I have been struggling with this and managed to get the user registered and the address record created in the DB with a 2-step form flow (first register user, then add address), but the address does not get linked to the user.
  
  Is this possible or perhaps I am trying something completely against the way craftcms/commerce works?
  
  **Tags:** plugin-craftcommerce, users, registration
  
  > **Comments:**
  > **username_1**: That should definitely work... are you successfully populating the userId field in the save-user form when saving the address?  
  > **username_0**: I think I figured out how this works. craftcms/commerce creates a "floating" customer as soon as a guest (not logged user) visits the page. In order to properly add addresses to a user (frontend) it has to be logged in.   So the process would be: register user -> activate -> user logs in -> user adds addresses.   I am thinking a way would be checking if the user has any registered address in the login form and:   - If they  have no addresses, set a redirect to the profile/add address form.   - If they already have at least one address, set a redirect to homepage.  
  
  ---
  
  ## 0 answers
  
  