Phenotypic plasticity of a cooperative behaviour in bacteria