Using below script we can able to get the product Hex code in magento2
$product_id = 1000; try{ $objectMansager = \Magento\Framework\App\ObjectManager::getInstance(); $productObj = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id); $colorOption = $productObj->getResource()->getAttribute('color')->getFrontend()->getValue($productObj); $colorOptionId = $product->getResource()->getAttribute('color')->getOptionId($colorOption); $attr = $productObj->getResource()->getAttribute('color'); $simpleProductHexCode = ''; if ($attr->usesSource()) { $attributeId = $attr->getSource()->getOptionId($colorOption); $resource = $objectMansager->get('Magento\Framework\App\ResourceConnection'); $connection = $resource->getConnection(); $tableName = $resource->getTableName('eav_attribute_option_swatch'); $sql = "Select * FROM " . $tableName." where option_id = ".$attributeId; $result_query = $connection->fetchAll($sql); echo $productHexCode = $result_query[0]['value']; } }catch(Exception $e){}