---
title: "How to Get a value of a Custom attribute of Product in Magento 2 Observer"
url: "https://magecomp.com/blog/get-value-custom-attribute-product-magento-2-observer/"
date: "2018-05-31T16:53:13+00:00"
modified: "2025-02-21T12:36:44+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 259
reading_time: "2 min read"
summary: "Considering the number of CMS available for eCommerce, Magento is popular &amp; powerful choices from small to large scale shops. Due to its unique features &amp; flexible architecture helps the de..."
description: "Placing a custom event before or after product save is used to trigger some action when the customer adds a product to cart. Follow this complete blog to get..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Submit Contact Us Data using GraphQL API in Magento 2"
    url: "https://magecomp.com/blog/submit-contact-us-data-using-graphql-api-magento-2/"
  - title: "How to Move Apply Coupon to Order Summary in Magento 2"
    url: "https://magecomp.com/blog/move-apply-coupon-to-order-summary-magento-2/"
  - title: "Magento 2: How to Add Dynamic Field in Product Create/Edit Form"
    url: "https://magecomp.com/blog/magento-2-add-dynamic-field-in-product-create-edit-form/"
---

# How to Get a value of a Custom attribute of Product in Magento 2 Observer

_Published: May 31, 2018_  
_Author: Dhiren Vasoya_  

![How to Get a value of a Custom attribute of Product in Magento 2 Observer](https://magecomp.com/blog/wp-content/uploads/2018/05/How-to-Get-a-value-of-a-Custom-attribute-of-Product-in-Magento-2-Observer-1024x332.webp)

Considering the number of CMS available for eCommerce, Magento is popular & powerful choices from small to large scale shops. Due to its unique features & flexible architecture helps the developer define their own events & observers by extending Native core functionality to fulfill store owner’s requirement.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

Basically, these observers are also known as “listener”, that helps you to detect specific events. And when an event takes place, it will perform an action defined by you. Compared to Magento 1, Magento 2 comes with the pretty well-integrated observer system that allows you to run your custom code in response to a specific Magento event or your custom event.

Basically, we want to perform a specific action, once a customer places an order. Here is an example where I have sales_order_save_after event observer.

[![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)

To do this, you just need to add event observer code in your **Observer file**.

```
public function execute(MagentoFrameworkEventObserver $observer)
{
	$order = $observer->getEvent()->getOrder();
	foreach($order->getAllVisibleItems() as $item )
            {
    		$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());

    if(array_key_exists("attributes_info",$options) && count($options['attributes_info']) >= 1) :

       // This code give all the custom attribute value
       foreach($options['attributes_info'] as $myopt)
       {
            echo $myopt['label']." : ".$myopt['value'];
       }

     endif;
}

}
```

You can play with this code and create your event & observer as per your requirement of adding one of more actions according to your needs.

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-6.webp)](https://magecomp.com/services/hyva-theme-development/)

Lastly, Comment down below if you face any issue while using this code.
Happy Coding!


---

_View the original post at: [https://magecomp.com/blog/get-value-custom-attribute-product-magento-2-observer/](https://magecomp.com/blog/get-value-custom-attribute-product-magento-2-observer/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-16 07:26:05 UTC_  
