To be able to assist you better, I would like to know the following:
What's the make and model of your WiFi router?
Do you have any antivirus software installed on your Mac?
Do you have a guest network enabled on your WiFi router?
Approximately how far is the printer located from the WiFi router?
Meanwhile, check this, there are chances of routers not being configured in bridge mode. Bridge mode means the router acts as purely an access point and not a router.
Could you also check with your ISP and make sure the connections are correct?
Keep me posted for further assistance.
TEJ1602 I am an HP Employee
Be alert for scammers posting fake support phone numbers and/or email addresses on the community. If you think you have received a fake HP Support message, please report it to us by clicking on "Flag Post".