Can you connect to a Minecraft not on your WiFi network?

There are two ways to connect to someone not on your LAN (your personal network, including WiFi/wireless and direct connection). The first and easiest is one of the players setting up a private Minecraft server, and then connecting to it like any other server.

The second, if for some reason hosting a server isn't an option, is to use VLAN, or virtual networking software, like Hamachi or Tunngle. This tricks your computers into thinking they're on the same network, even when they're miles apart, and lets you connect to each other via LAN.