The only difference is how the neighbors of any site are labeled. Both are bipartite lattices; for the square lattice each site has four neighbors on the other sublattice, while for the hineycomb lattice, each site has three. So the only part of the code that needs to be changed is the routine that computes the sum over the neighbors.
This exercise is quite known, it is explained in detail on the article published by S. Akbar Jafari on: International Journal of Modern Physics B Vol. 23, No. 3 (2009) 395–401. DOI: 10.1142/S0217979209049620
You can even find work on randomized lattices, in case you look for a further complicated case.