Detect and measure fog outdoors
Get a humidity sensor, when it reads out 100% RH then you know it's foggy (you don't know what the visibility is however). You can get humidity\pressure\temperature sensors from bosch for cheap (3x3mm or something like that). Like the BME280

Other than that maybe a photogate like device would be a cheap way to measure fog or a combination of both.