Prove that $G$ is abelian iff $\varphi(g) = g^2$ is a homomorphism

I'm working on the following problem:

Let $G$ be a group. Prove that $G$ is abelian if and only if $\varphi(g) = g^2$ is a homomorphism.

My solution: First assume that $G$ is an abelian group and let $g, h \in G$. Observe that $\varphi(gh) = (gh)^2 = (gh)(gh) = g^2h^2 = \varphi(g)\varphi(h)$. Thus, $\varphi$ is a homomorphism.

I'm having trouble completing the proof in the reverse direction. Assume that $\varphi$ is a homomorphism. We then know that $\varphi(gh) = \varphi(g)\varphi(h)$ and $\varphi(hg) = \varphi(h)\varphi(g)$. However, I don't see a way to use this to show that $gh = hg$.

Could anyone lend a helping hand?


Proof without words: $$abab=aabb$$ $$bab=abb$$ $$ba=ab$$


Write out both sides of the equation you get. What is $\varphi(gh)$ explicitly? What's $\varphi(g)\varphi(h)$ explicitly? Conclude from there.