Drupal 7 appending class in uc attribute option radio button I have this code inside mymodule_form_alter:

     foreach ($form['attributes'] as $att) {
        foreach ($att['#options'] as $option =&gt; $value) {
  // Get the name of the option without the price or price adjustment -&gt; string before coma
            $optionName = explode(",", $att['#options'][$option], 2)[0];
            if (strpos($optionName, '+') !== false) {
                $att['#options'][$option]['#attributes'][] = array('class' =&gt; array('my_class'));
            }
        }
    }


Unfortunately


  $att['#options'][$option]['#attributes'][] = array('class' =>
  array('my_class'));


Displays unexpected error, I tried different syntax but no success. Any help much appreciated


  Update 27/09/2017


I tried to do this by using after_build I get no errors but it isn't working

// Inside hook_form_alter
 $form['attributes']['#after_build'][] = 'addToCartFormEditQuantity_after_build';

 function addToCartFormEditQuantity_after_build(&amp;$element, &amp;$form_state)
{
    // Each renderable radio element.
    foreach ($element as $attribute) {
        foreach (element_children($attribute) as $option) {
            var_dump($attribute[$option]);
      // Get the name of the option without the price or price adjustment -&gt; string before coma
            $optionName = explode(",", $attribute['#options'][$option], 2)[0];
            if (strpos($optionName, '+') !== false) {
                $attribute[$option]['#atrributes']['class'] .= 'single-double';
            }
        }
    }

    return $element;
}
I managed to get what I wanted  inside theme_uc_attribute_add_to_cart by using:

foreach (element_children($form) as $aid) {
     foreach (element_children($form[$aid]) as $option) {

        $form[$aid][$option]['#prefix'] = '&lt;div class="row single-double"&gt;';
        $form[$aid][$option]['#suffix'] = '&lt;/div&gt;';

      }
    }


But I really don't want to mess with uc_attribute.theme.inc is there any other way?