1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. User fields
  5. Populate add-on field options with user fields
  1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Populate add-on field options with user fields
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Populate add-on field options with user fields
  1. Home
  2. Knowledge Base
  3. Advanced Topics for Add-Ons Ultimate
  4. Populate add-on field options with user fields

Populate add-on field options with user fields

Using Add-Ons Ultimate and Members Only, you can populate add-on field options (e.g. for a select or radio group field) with data from a user field.

To enable the feature, first go to WooCommerce > Settings > Product Add-Ons > Integrations and check the ‘Enable user fields’ option.

WooCommerce custom user fields option for add-on fields

Create a custom user field with Members Only

You must have used Members Only to create a new custom user field. Go to WooCommerce > Settings > Members Only > User Fields and expand the field that you want to use.

The field that you want to use to populate your options must be a ‘Text’ field and it must have the ‘Repeater’ option enabled.

WooCommerce user field setting for text field

You can then get your field ID from the same section.

WooCommerce custom field ID

Make a note of this ID.

Enable Add-Ons functionality

Then you can create an add-on field as normal. In this example, we’ll create a ‘Select’ field. We’ll use a special tag to automatically populate the options with the current user’s data.

Automatically populate add-on field options with user data

Select the field type, then click ‘Add Option’. In the ‘Label’ field for the first option, enter a tag like this:

{user_field:12345678xx}

Replace the field ID with your own custom user field ID.

Save the product. The user will now be able to select an option from any values they’ve previously added to this user field.

Adding a new custom user field value from the product page

If you’d like the user to be able to add a new option to the custom user field direct from the product page, you’ll need to add a checkbox and a new text field after your select field.

Add the checkbox

The checkbox is to give the user the option to add a new option and ensures that an existing name doesn’t get passed to the order.

Checkbox field setting

Note that we’ve set ‘Field Visibility’ to ‘Display on product page only’ because we don’t need the value of this field to be sent to the order. We’ve also enabled the ‘Display as Swatch’ option to display the checkbox as a clickable text swatch – like a button – rather than just a standard checkbox. This part is optional.

We’ve also added a condition to ensure this field only displays to users who are logged in.

Add the text field

Now add your text field and, in the ‘User Field ID’ setting, add the same field ID that you used in the step above.

WooCommerce custom field ID setting

Note that we’ve added a condition to this field so that it only displays if the checkbox is selected.

We’ll also need to go back to the select we added initially and add a condition there so that it’s not displayed if the checkbox is checked. We also add a condition to ensure the field is not displayed if the user is not logged in.

Add-on field for user custom data

The user will now be able to add a new value for this custom field that will get saved to their profile.

Ensure that fields only appear for logged-in users

To ensure that the above fields are only display

Was this article helpful?

Related Articles