If there is a schoolhouse, cemetery or church building located upon school land or land of the state which has been or may be sold to any individual, corporation or parties, such school district, church or association, with the written consent of the purchaser or occupant, may purchase land for the purposes specified, and obtain a deed from the state, at the price the purchaser, assignee or occupant is to pay. The sum so paid for the tract obtained for such special purpose shall be deducted from the price the original purchaser was to pay.