In my Drupal Commerce site, I have a product type - an attribute which refers to another product type (via reference product).

The display is:

Type 1

Product 1-1 x

Product 1-2 x

Product 1-3 x

Add to Cart

Type 2

Product 2-1 x

Product 2-2 x

x produces 2-3

Add to Cart

I would like only one "add to cart" button to be visible, and that clicking it should add two products which were selected at the same time.

How can this be accomplished?


I would do this with rules:


After adding a product to the cart


Add a product to the cart

  • Parameter: User: [site:current-user],
  • Product SKU: [other product sku] Provides variables: Added product line item (product_add_line_item)

You can alter add to cart form and insert there your own submit.

$form['#submit'][] = 'my_own_submit';

Than in your submit you can do anything you want.

E.g. you can get your product from $form_state. Than you can load related product and add it to cart by drupal commerce API. Example of adding product to cart is here

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.