Buy more hats than you think you’re ever likely to need. Buy at least 5.
Keep one under the pram, one in the car, one in your handbag, one in their baby bag, one near the door, another one in your other car if you have 2 cars. Any extras store in their cupboard.
This way when you rush out the door you have appropriate head wear. Wooly warm ones in winter, sun protective ones in summer.
Chances are you’ll need more than 5 as hats seem to miraculously disappear.