"palm tree," 1550s, from Spanish and Portuguese coco "grinning or grimacing face," on resemblance of the three depressions at the base of the shell to a monkey or human face. The earlier word for it was the Latinized form cocus, which sometimes was Englished as cocos.
"brown powder produced by grinding roasted seeds of the cacao, an American evergreen tree," 1788, originally the seeds themselves (1707), corruption (by influence of coco) of cacao. The confusion with coco was already underway in English when the printers of Johnson's dictionary ran together the entries for coco and cocoa, after which it has never been undone. Cocoa has been the regular spelling from c. 1800.