The messaging applications themselves should have a status and/or visibility mode to prevent others from seeing you are online, you shouldn't need to do anything on the Mac itself.
I use several and most can't be seen. However, I live in Ecuador where almost everyone, including businesses, use WhatsApp. I am able to go incognito on my phone but not on the desktop version.
That is a limitation of WhatsApp for desktop then. Even if you were to "hide" your Mac, WhatsApp would still show you as online unless they add incognito mode.