I was building an e-commerce website using woocommerce and one of the requirements was to make the client register/login before they are allowed to see any content. I looked around to see how to achieve that and I came up with the solution below. What the code does is, it checks if the user is not logged in and its not on page number 7 (which is the ID of my registration page).

So, if the user is logged in, that code will not be executed. If the user is on the registration page (with ID of 7), again it will not be executed. It will only be executed if the user is NOT logged in and is NOT on page with ID=7. You should obviously change that number to the according ID of the page you want from your database. I think I am taking too long to explain a simple line of code, you better copy and examine it by yourself.

If you find my blogging useful, please share it.