Using Drupal Commerce I have created product variations with attributes that correspond to my taxonomies. When I use radio buttons to allow the user to select a specific variation Drupal Commerce adds a hyphen to the start the radio button label. For example my taxonomy term is 'White gold' but the radio button label that is displayed is '-White gold'.

How do I stop these hyphens from being added?

Screenshot of hyphens before radio button labels

2 Answers 2


These hyphens are not being added by Drupal Commerce itself, so you'll need to look into what other modules on the site might be interacting with the form.


It's probably an effect of the use of nested taxonomy terms there. In particular the function


 * Returns the set of valid terms for a taxonomy field.
 * @param $field
 *   The field definition.
 * @return
 *   The array of valid terms for this field, keyed by term id.
function taxonomy_allowed_values($field) {
  $options = array();
  foreach ($field['settings']['allowed_values'] as $tree) {
    if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
      if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'])) {
        foreach ($terms as $term) {
          $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
  return $options;

This part here:

$options[$term->tid] = str_repeat('-', $term->depth) . $term->name;

Adds a hyphen prefix to the term based on the term depth in the vocabulary.

It's called by taxonomy_options_list

You could actually add your own option_list function by adding this to the term_reference field settings:

$field['settings']['options_list_callback'] = 'my_module_taxonomy_options_list';

Alternatively you may be able to form_alter them out from display with

hook_form_commerce_add_to_cart_form_alter(&$form, &$form_state);
  • Thanks David Thomas, you clearly explain what the problem is, and suggest some starting points that look very helpful. Yes, I am using nested taxonomy terms. I tried to start using your second suggestion, but I am quite new to customising Drupal. As a test of whether the hook was being called, in my template.php I added function hook_form_commerce_add_to_cart_form_alter(&$form, &$form_state) { drupal_set_message(t("Add to cart being shown"), 'status'); } The message does not show when I go to my product page. I have tried clearing my cache. Any suggestions what I am doing wrong? Commented Dec 3, 2013 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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