---
title: "Magento 2: How to Add Group Product into Cart Individually"
url: "https://magecomp.com/blog/magento-2-add-group-product-into-cart-individually/"
date: "2022-12-16T11:57:23+00:00"
modified: "2025-02-14T09:37:04+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 775
reading_time: "4 min read"
summary: "Hello Magento Friends,"
description: "Learn How to Add Grouped Product into Cart Individually in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Get Product Salable Quantity in Magento 2?"
    url: "https://magecomp.com/blog/get-product-salable-quantity-magento-2/"
  - title: "How to Override “payment\methods.phtml” in Magento Custom Extension"
    url: "https://magecomp.com/blog/override-paymentmethods-phtml-in-magento-custom-extension/"
  - title: "Magento 1 to Magento 2 Migration -What you need to know"
    url: "https://magecomp.com/blog/migrate-from-magento-1-to-magento-2/"
---

# Magento 2: How to Add Group Product into Cart Individually

_Published: December 16, 2022_  
_Author: Dhiren Vasoya_  

![How to Add Group Product into Cart Individually M2](https://magecomp.com/blog/wp-content/uploads/2022/12/How-to-Add-Group-Product-into-Cart-Individually-M2-1024x512.webp)

**Hello Magento Friends,**

In today’s Magento tutorial guide, I will explain How to Add Group Product into Cart Individually in Magento 2.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-4.webp)](https://magecomp.com/services/hire-magento-programmer/)

Suppose you have two simple products associated with grouped products on the product detail page and have a separate add-to-cart button for each product. When you press the add to cart button for the first product, both products are added. If you want to add individual products to the cart for grouped products in Magento 2, use the following steps.
## Steps to Add Group Product into Cart Individually in Magento 2:
**Step 1:** You need to override the **grouped.phtml** file in your theme. For that, go to the below file path.
**app\design\frontend\Theme\Yourtheme\Magento_GroupedProduct\templates\product\view\type\grouped.phtml**

And add the code as follows.
```
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Grouped product data template
 *
 * @var $block MagentoCatalogBlockProductViewBaseImage
 * @var $block MagentoGroupedProductBlockProductViewTypeGrouped
 */
?>

<?php $block->setPreconfiguredValue(); ?>
<?php $_product = $block->getProduct(); ?>
<?php $_associatedProducts = $block->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php $grouped = $_product->load($_product->getId()); ?>
<?php $associatedProducts = $grouped->getTypeInstance()->getAssociatedProducts($grouped); ?>

</form>

    <table class="table data grouped" id="super-product-table">
        <caption class="table-caption"><?= /* @escapeNotVerified */ __('Grouped product items') ?></caption>
        <thead>
            <tr>
                <th class="col item" scope="col"><?= /* @escapeNotVerified */ __('Product Name') ?></th>
                <?php if ($_product->isSaleable()): ?>
                    <th class="col qty" scope="col"><?= /* @escapeNotVerified */ __('Qty') ?></th>
                <?php endif; ?>
            </tr>
        </thead>

        <?php if ($_hasAssociatedProducts): ?>
        <?php foreach ($associatedProducts as $_item): ?>
        <tbody>
            <tr>
                <td data-th="<?= $block->escapeHtml(__('Product Name')) ?>" class="col item">
                    <strong class="product-item-name"><?= $block->escapeHtml($_item->getName()) ?></strong>
                    <?php if ($block->getCanShowProductPrice($_product)): ?>
                        <?php if ($block->getCanShowProductPrice($_item)): ?>
                            <?= /* @escapeNotVerified */ $block->getProductPrice($_item) ?>
                        <?php endif; ?>
                     <?php endif; ?>
                </td>
                <?php if ($_product->isSaleable()): ?>
                    <td data-th="<?= $block->escapeHtml(__('Qty')) ?>" class="col qty">
                        <?php if ($_item->isSaleable()) : ?>
                                                            <form data-role="tocart-form" action="<?php echo $this->getAddToCartUrl($_item); ?>" method="post">
                                    <input type="hidden" name="product" value="<?php echo $_item->getId(); ?>">
                                    <input type="hidden" name="related_product" id="related-products-field" value="">
                                    <input type="number"
                                       name="qty"
                                       value="<?= /* @escapeNotVerified */ $_item->getQty() * 1 ?>"
                                       title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                                       class="input-text qty required"
                                       />

                                    <?php echo $block->getBlockHtml('formkey')?>

                                    <button type="submit" title="Add to Cart" class="addtocart">Add to Cart</button>
                                </form>

                        <?php else: ?>
                            ">
                                <?= /* @escapeNotVerified */ __('Out of stock') ?>                                                    <?php endif; ?>
                    </td>
                    <td class="addtocart">
                    </td>
                <?php endif; ?>
            </tr>
            <?php if ($block->getCanShowProductPrice($_product)
                && $block->getCanShowProductPrice($_item)
                && trim($block->getProductPriceHtml(
                    $_item,
                    MagentoCatalogPricingPriceTierPrice::PRICE_CODE
                ))): ?>
                <tr class="row-tier-price">
                    <td colspan="2">
                        <?= $block->getProductPriceHtml(
                            $_item,
                            MagentoCatalogPricingPriceTierPrice::PRICE_CODE
                        ) ?>
                    </td>
                </tr>
            <?php endif; ?>
        </tbody>
        <?php endforeach; ?>
        <?php else: ?>
            <tbody>
                <tr>
                    <td class="unavailable"
                        colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>">
                        <?= /* @escapeNotVerified */ __('No options of this product are available.') ?>
                    </td>
                </tr>
            </tbody>
        <?php endif; ?>
    </table>

<form>
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

**Step 2:** After that, you need to run the below command.
```
sudo php bin/magento cache:flush
```

## Conclusion:
This way, you can add group products into the cart individually in Magento 2. Also, learn [**How to Create Grouped Product Programmatically in Magento 2**](https://magecomp.com/blog/create-grouped-product-programmatically-magento-2/).
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2023/10/Magento-2-Speed-Performance-Optimization-Services-CTA-4.webp)](https://magecomp.com/magento-performance-optimization.html)

If you have difficulty with the above solution, share it with me by commenting here. Share the article with your friends and stay updated with us for more Magento 2 tutorials.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/magento-2-add-group-product-into-cart-individually/](https://magecomp.com/blog/magento-2-add-group-product-into-cart-individually/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 12:41:09 UTC_  
