Play Act 1 Chapter 3, "Rolling Thunder", under the Insane difficulty setting. Shoot the three hidden cowboy hats at the start of the chapter. You and all the COG will wear cowboy hats for the rest of the level.
Additionally, a Corpser that appears from the ground later in the chapter will wear a cowboy hat and shout "Yee haw".