I am using Ubercart 3 on Drupal 7 for my website.

How am I able to have two "Add to cart" button on a product page that use two different attributes? So for example I can have:

(Buy the large version) (Buy the small version)

Those two buttons match my attributes that I have set in the back, so customers can click on one of those and add the product to the cart directly.

1 Answer 1


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.

You can,

  • 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 (o2).

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.

<div id="buy-large">
 print l(
      t('Buy the large version'), 
<div id="buy-small">
 print l(
      t('Buy the small version'), 

if you are putting this code in a block or anywhere other than node.tpl.php or variants, change $node->nid to 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.

Good luck!

  • Just to let you know this websites only allows me to award you my bounty tomorrow, but I do have this in mind :)
    – Luca
    Sep 11, 2012 at 3:53
  • Hello again, just an update that the link should be actually "cart/add/e-p123_a1o2" since cart links module split the arguments using underscore "_", and then it works great! Thank you
    – Luca
    Sep 11, 2012 at 16:00
  • sorry for that mistake. anyway great to hear that you got it working.cheers!
    – AKS
    Sep 11, 2012 at 16:25
  • Thank you for the great answer, might be ideal if you edit that bit so others can benefit as well. Really appreciate that
    – Luca
    Sep 12, 2012 at 3:06

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.