A. Enable Ubercart Cart Links (part of core).
B. Add necessary attributes and make sure you have a default attribute set.
With UC cart links, you can perform the add-to-cart functionality with many different AND DYNAMIC arguments. Without making a new add-to-cart button using Form API or complicated setups.
Add any quantity of any number of products to the customer's cart, with specific attributes and options for each added product, if applicable.
Display a custom message to the user.
Track the click for display on a store report.
Empty the customer's shopping cart.
Redirect to any page on the site.
Basically you make a URL that will, when opened, adds given items with given parameters to the current user's cart.
See above link. When opened, it will first empty the cart (
e), adds product/node ID 123 to the cart(
p123) with attribute of ID 1 (a1) and that attribute's option ID 2 (
You can see a very good help instructions on help section of uc_cart_links module's admin page (admin/help/uc_cart_links) .
You can build the URLs using Drupal's url() or l() functions.
Put these snippets in your node.tpl.php file of the product node type (node--product.tpl.php) where you want to display buttons.
t('Buy the large version'),
t('Buy the small version'),
if you are putting this code in a block or anywhere other than node.tpl.php or variants, change
arg(1) . This
arg(1) thing will only work if the button is being displayed in full content page.
if you are placing these buttons in a View, replace
$node->nid with the appropriate node ID by adding a node: ID field and tokens.
If you want to see attribute and option IDs, go to attributes page and you will see the attribute/option ID which is a numeric one.