Men wearing hats is still quite common today. But the style has changed to baseball caps and similar forms. Most of those "dress codes" usually also have a more practical origin. So it's less of a code, and more a practical benefit.