I'm creating a plugin to disable Cart on WooCommerce (even I know already some plugin doing this), I already removed the button to access cart page.

But how can I check if url is /cart? WordPress have some function to get it?

What I need to do is like:

if (is_cart()) {

I tried to use is_cart function as said in WooCommerce doc, but seems not working for me.


1 Answer 1


I'm not sure where are you hooking your function to, but you might be doing it too early.

Hook to template_redirect, and then redirect the user:

function redirect_visitor(){
    if ( is_page( 'cart' ) || is_cart() ) {
        exit(); // Don't forget this one
  • Just a sidenote, that parse_query also works and is earlier Jan 15, 2020 at 23:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.