Yes. Let $T$ be the theory of two disjoint groups, in the language $(\cdot_1, \cdot_2, U_1, U_2)$. Note that if $(G_1, G_2) \models T$ then the group operation on $G_1 \times G_2$ is definable without parameters. Thus we can recover the theory of $G_1 \times G_2$ from the theory of $(G_1, G_2)$, which is clearly determined by $(\mbox{Th}(G_1), \mbox{Th}(G_2))$. Thus if $G_1, G_2, G_1', G_2'$ are any groups with each $G_i \equiv G_i'$, then $G_1 \times G_2 \equiv G_1' \times G_2'$.