In most cases you can buy a ticket for someone else, even if they live in another city, if the payment method you are using is accepted in the country where you are making the purchase. Otherwise, the passenger will not be admitted to the flight and will have to buy a new ticket on the spot. In any case, this will be indicated during the purchasing process, when you reach the payment page.
This is one of the reasons why we advise against paying with virtual cards.