An invitation to visit is evidence that they treat you well and will be happy to chat with you in an informal setting. However, sometimes such an invitation goes against your plans and desires. Then you have to solve the problem: how to save your time and not offend your friends.
If you cannot come to visit for objective reasons, apologize to your friend and explain why the meeting will not take place. Say that you are very sorry about this and hope to meet later. Your friend will be pleased if you yourself invite him to visit when it is convenient for both of you.
Perhaps you assume that the visit will not be very interesting and you will be wasting your time. If you find it inconvenient to honestly explain the reason, refer to being busy - you don't have to go into details. If your friend insists, you can refer to some mysterious circumstances: "There are problems … I'll tell you later - I can't now." You will have time to come up with a version if your friend shows curiosity in the future.
If you are invited to a family celebration, be sure to call that day and congratulate your friends on a happy event. Confirm once again how sorry you are that you cannot attend in person. If the reason for the invitation was an ordinary party of friends, call the next day and ask how it went.
After you have accepted the invitation, it will be very impolite not to visit. Illness, natural disaster, or the unexpected arrival of relatives can be a good reason for a sudden refusal. Be sure to warn the hosts that you won't be able to be, and apologize politely.
You may have received a new, more interesting offer after accepting the invitation. If you want to refuse a visit you've already made, think about letting your friends down. They plan a budget and possibly a holiday scenario and count on your presence. In addition, your refusal for this reason, most likely, will greatly offend them.
If you try to refuse a visit under a plausible pretext, the truth may surface at any time, especially if you have mutual acquaintances in the new company. In this case, you run the risk of seriously ruining your relationship with friends.