The 25-year-old is currently the club’s top scorer this season.
The former Chelsea ace said: “I am very pleased to sign. It is nice that I can just focus on playing good football.
“I know now I am here for quite a while so it is time to knuckle down.
“The manager Gianfranco Zola has 100 per cent faith in me and I have 100 per cent faith in him and our team as well.
“It is good that I’ve got this opportunity to show West Ham fans, and prove to myself, that I can be a big part of the prospects to come. The only way is up.”
Chief executive Scott Duxbury insisted: “This news underlines that as a club we are thinking only of moving forward and are on a sound financial footing.”