Oh snap! You are using an old version of browser. Update your browser to get new awesome features. Click for more details.

Magento 2 To get product attributes of specific attribute group id


Hello Friends,

Get specific attribute collection by attribute group id in product page. Use below code. First get your group id and attribute_set_id in eav_attribute_group table.

Then use this code.

//$_product is current product object
$productAttributes = $_product->getAttributes();
$group_id = 104; //Past Your Attribute Group Id
$attributeSetId = 16; //Past Your Attribute Set Id

foreach ($productAttributes as $attribute) {

    if ($attribute->isInGroup($attributeSetId, $group_id)) {

        if ($attribute->getFrontend()->getValue($_product)) {
            echo 'Attribute Label: '.$attribute->getFrontendLabel().'<br>';
            $valueArray = explode(",",$attribute->getFrontend()->getValue($_product));

            foreach ($valueArray as $valuesArray) {
                echo 'Attribute Value: '.$valuesArray;
                echo '<br>';
            }

        }

    }

}

3 comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. kardinal stick

    ReplyDelete