0

I have a custom line item type that has a List(Text) field. When I do this:

$line_item = commerce_line_item_load($lid);

I get an object that contains the value, but not the label of the selected option.

$line_item->field_ring_size[LANGUAGE_NONE][0]['value'] // returns 2 instead of, say, Large

How can I get the value's label instead?

I've tried using field_info_instance to get all values, as follows:

$info = field_info_instance('commerce_line_item', 'field_ring_size', 'ring_setting');

...but this does not return the values as far as I can see. Similarly, I've tried field_get_items, but this gives me the key back again.

How can I get the value (or a list of all values) instead of the key?

1

You can do it using list_allowed_values function

  $field = field_info_field('field_name');
  $allowed_values = list_allowed_values($field);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.