I am able to create an add to cart button:

$nid = 27;
$node = node_load($nid);
$add_to_cart = array( 
    '#theme' => 'uc_product_add_to_cart',
    '#form' => drupal_get_form('uc_product_add_to_cart_form_' . $nid, $node) 
return drupal_render($add_to_cart);

This gives me an add to cart button, but with no attributes selected. How can I alter this code to allow for the defaults to be set to specific values. For example, if I have an attribute with aid = 1, called "action", and two possible value... oid = 3 = register ... and oid = 4 = transfer..... of which I want the default to be "transfer" for example?

2 Answers 2


I managed to use cart links instead:


This is the updated updated and more correct answer:

$node = node_load(123);
$drupalForm = drupal_get_form('uc_product_add_to_cart_form_' . $node->nid, $node);
$addToCartHTML = drupal_render($drupalForm);

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.