Get product attribute’s option id from label and get option label from id in magento 2.

In Magento 2 We can get product Attributes Option Id from the Label and Option label by Option id with Product  Factory object.

Occasionally when you work with the Configurable Product type you may face situations to get Option Id or Label from the Attribute code.

Lets We have taken a Color attribute to demonstrate the usage, Find a Color Label value based on Color Option id.

Call Method at the specific file,

Assume that, We have Option id 50 and its value is Blue from Attribute code Color.

getOptionIdByLabel() and getOptionLabelByValue() method will be use to get Option Id By Label value and Option Label by Option Id  respectively.

You need to pass only the correct Product Attribute code you want to fetch the value. The given example is working fine for all the custom product attributes in Magento.