Skip to content

How to add products to cart similar to related products?

For a client we have a case where we want to be able to add products to the cart in the same way you do with related products using checkboxes on a PDP (default magento).
When I look at the code for the related products it looks like this:

<div class="field choice related"> 
<input type="checkbox" class="checkbox related" id="related-checkbox17" name="related_products[]" value="17">
<label class="label" for="related-checkbox17">
<span>Add to Cart</span></label>
</div>

I dont see any additional javascript and it is not part of any form. I dont understand how this magically works, I think it has something to do with name=”related_products[]”. There is also no SKU to be found here. When I add similar code on the PDP it does not work. What is the underlying mechanism here? What are the minimal requirements to make it work? As in: when the user clicks on the add to cart button it should add those extra products to the cart in addition to the main product.