From the course: WordPress Ecommerce: WooCommerce Plugins

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Hide the checkout page

Hide the checkout page

From the course: WordPress Ecommerce: WooCommerce Plugins

Start my 1-month free trial

Hide the checkout page

- [Voiceover] You may have noticed that our function runs all the time, and that's a problem. We really only want it to run on the checkout page. And, of course, we want it to do something smarter than display a white page. So we're going to use a Woo Commerce function to help with this. There's a ton a conditional tags in Woo Commerce to check for certain things. What we're going to want to use is is_checkout(). Which is right here. And this conditional will return true when were on the checkout page. So, I'm going to go back to my code, and in the maybe_disable_checkout() function, instead of echo and exit, I'm going to add, && is_checkout(). Now if we save this and go back to our home page, it's no longer running on the home page. If you go to the cart, totally fine. And if you go to the checkout, that's when you get that error. So this conditional is very useful, to make sure that we're only running code on the right pages. Now on to the second problem, the fact that it's just a…

Contents