There is strong evidence that natural selection can favour phenotypic plasticity as a mechanism to maximize fitness in animals. Here, we aim to investigate phenotypic plasticity of a cooperative trait in bacteria--the production of an iron-scavenging molecule (pyoverdin) by Pseudomonas aeruginosa. Pyoverdin production is metabolically costly to the individual cell, but provides a benefit to the local group and can potentially be exploited by nonpyoverdin-producing cheats. Here, we subject bacteria to changes in the social environment in media with different iron availabilities and test whether cells can adjust pyoverdin production in response to these changes. We found that pyoverdin production per cell significantly decreased at higher cell densities and increased in the presence of cheats. This phenotypic plasticity significantly influenced the costs and benefits of cooperation. Specifically, the investment of resources into pyoverdin production was reduced in iron-rich environments and at high cell densities, but increased under iron limitation, and when pyoverdin was exploited by cheats. Our study demonstrates that phenotypic plasticity in a cooperative trait as a response to changes in the environment occurs in even the simplest of organisms, a bacterium.