Try this, hope this is what looking for

    if ($product->getCustomAttributes()) {
            $attribute_value = $product->getCustomAttribute('attribute_code') ?  $product->getCustomAttribute('attribute_code')->getValue() : '';
            return $attribute_value;
    }
    
Try it and do let me know.
Peace :)