How do you use hook_form_alter to add to cart form (ubercart) since their form id is uc_product_add_to_cart_form_[nodeID]. Thus, each product has their own add to cart form. If we want to alter some stuff on that form... for a ton of products... well you get the idea.

Comments

jaypan’s picture

In the past I've used:

if(preg_match('/uc_product_add_to_cart_form_\d+$/', $form_id))
{

}

You may also want to look at hook_forms(), it could possibly solve your problem.

Contact me to contract me for D7 -> D10/11 migrations.

halloffame’s picture

How about iterating form elements?

$form['items'][0]['desc']['#value']
$form['items'][1]['desc']['#value']
$form['items'][2]['desc']['#value']
so on and so forth...

Will foreach work in this case?