How to stop your plugin from executing on certain pages?

I'm building a plugin that extends WooCommerce and I want to prevent it from executing once it hits the template_redirect hook. My goal is to stop the plugin from loading all the assets on non-product pages. Any ideas on how to do this?

Code

add_action('template_redirect', array($this, 'stoplight'));

function stoplight() {
        $post_type = get_post_type();
        if ($post_type != 'product') {
            return;
            //I used wp_die() here as well, but it killed WordPress.
        }
    }

Topic plugin-development Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.