{"id":1544,"date":"2021-01-30T04:41:33","date_gmt":"2021-01-30T04:41:33","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-product-attribute-set-name-in-magento-2\/"},"modified":"2025-11-29T12:32:04","modified_gmt":"2025-11-29T07:02:04","slug":"get-product-attribute-set-name-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-attribute-set-name-in-magento-2\/","title":{"rendered":"How to Get Product Attribute Set Name in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The list of attributes that define the characteristics of a product is called&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-attribute-set\/\" target=\"_blank\" rel=\"noreferrer noopener\">attribute sets<\/a>. Any information that makes the product unique can be displayed using product attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While working with attributes, you may also need to <a href=\"https:\/\/meetanshi.com\/blog\/get-product-options-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">get product options in Magento 2 <\/a>programmatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a store with thousands of products, it can be tiresome to handle its information like attributes, attribute sets, etc. And, a store owner often needs to get the details of the attribute set in order to update the product or for displaying it categorically in the frontend based on its properties.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Be it for updating the products or improving the in-store experience, it is often the admin\u2019s requirement to&nbsp;get product attribute set name in Magento 2&nbsp;and the post shows the programmatic solution for the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Get Product Attribute Set Name in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Magento\\Catalog\\Model\\Product;\nuse Magento\\Eav\\Api\\AttributeSetRepositoryInterface;\n\nprotected $product;\nprotected $attributeSetRepository;\n\npublic function __construct(\n    Product $product,\n    AttributeSetRepositoryInterface $attributeSetRepository)\n{\n    $this->product = $product;\n    $this->attributeSetRepository = $attributeSetRepository;\n}\n\npublic function getAttributeSetName($productId)\n{\n    $product = $this->product->load($productId);\n    $attributeSet = $this->attributeSetRepository->get($product->getAttributeSetId());\n    return $attributeSet->getAttributeSetName();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above code will print the names of the attribute set related to the product.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/01\/ss-1024x508.jpg\" alt=\"attribute set\" class=\"wp-image-12689\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The list of attributes that define the characteristics of a product is called&nbsp;attribute sets. Any information that makes the product unique can be displayed using&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1544","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1544\/revisions"}],"predecessor-version":[{"id":24518,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1544\/revisions\/24518"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}