The ports are soldered onto the main logic board so you can't replace them.
Are the cords slipping out or are they firmly connected? Is a given socket having problems?
If they are firmly connected and one socket has more of an issue, then you maybe able to fix this by tagging the solder joints (after pulling the logic board out). It's possible you just have a cold joint. This is still a bit of work and is not something I recommend for a first timer to do.
If you are loosing connection without touching the cord or the device then you may have a power issue via the USB port. Start by getting a powered USB hub and then connect it to your system with the USB devices connected via the powered hub. Is this working better? If so you may need to check the USB fuse links on the logic board as they maybe blown. These are small SMT components and do require a bit of skill to test & replace. See if you have an electronics repair person nearby who has the skills set and the needed SMT fuse link part (Apple authorized service center Vs an Apple Store).
If the cords are not firmly holding you might be able to reshape the cord connector so it is pushing against the friction point of the socket harder (don't over do it!) or try a fresh cord to see if its the cord thats bad.
As to replacing your laptop Vs repairing:
I would fix it (or have someone fix it) as it still a useful system. If your system is overly beaten up then maybe its time for a new system.