In my Drupal 8 template, I use {{ product.variations }} which produces the following HTML markup.

<div data-drupal-selector="edit-actions" class="form-actions js-form-wrapper form-group" id="edit-actions--2">
  <button class="button--add-to-cart button button--primary js-form-submit form-submit btn btn-primary" data-drupal-selector="edit-submit" type="submit" id="edit-submit" name="op" value="Ajouter au panier">Ajouter au panier</button>
  <span>Ajouter au panier</span>

How do I remove the <button> part from it?

I tried using {{ product.variations|without('button', 'submit') }}, but it doesn't work.

  • 1
    That won't prevent raw html elements from appearing. Without only suppresses render elements. drupal.org/docs/theming-drupal/twig-in-drupal/…
    – Kevin
    Feb 8, 2021 at 2:25
  • 1
    Use CSS: .form-actions { display: none;} Feb 8, 2021 at 4:23
  • @Jorge Montoya I prefer to remove HTML instead of using CSS.
    – user101865
    Feb 8, 2021 at 5:46
  • 1
    Why would you need to remove the submit button of a form? What do you need the form for then at all?
    – leymannx
    Feb 8, 2021 at 12:32

1 Answer 1


If I understand correctly, and if my french (google translate :P) is precise.. you wish to remove the add to cart button from your variations.

In that case I see two options. If you wish to just hide the button in some view modes, like a teaser or whatever, just use the THEME/HOOK_form_commerce_order_item_add_to_cart_form_alter and try to remove the submit action. Having said that, I can not guarantee the HTML validity of a form without a submit button or how it will work with the form action, since I have not tested it, but I guess it won't be a problem.

On the other hand, if you just want non purchasable variations, you could try this patch out and let the issue maintainers know how it worked :D

Let me know what worked for you,

Best Regards

  • Maybe $form['some_submit']['#attributes']['style']['display: none;'] or $form['some_submit']['#attributes']['class']['element-invisible'].
    – leymannx
    Feb 8, 2021 at 10:16
  • @leymannx The poster wants to remove the html completely so I was thinking something along the lines of $form['some_submit']['#printed'] = TRUE; but to provide exact code I would have to test it first :P Feb 8, 2021 at 11:36
  • Then it's unset($form['some_submit']);. But as you said: Not sure if form works then anymore and how you will be able to submit it at all.
    – leymannx
    Feb 8, 2021 at 12:30
  • Well yeah.. kinda.... I always prefer to set $form['some_submit']['#printed'] = TRUE; or $whateverElement['#printed'] = TRUE for that matter, when i wish to hide something. Feb 8, 2021 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.