The best way to keep websites safe from hacks is to keep it updated.
Whichever Content Management System or e-commerce platform you’re using to build and manage your site, keep up with updates. Sign up for security announcements. Set auto-updates where possible.
These links to common Content Management Systems and e-commerce platforms will give you more information about what you should and shouldn’t be doing: