WooCommerce Logged Out User: Hide Products & Pages

The following code will hide WooCommerce products and pages for any logged out users, as well as redirect to the homepage.

Happy developing!

// redirecting woocommerce pages to homepage for logged out users
add_action('template_redirect', 'fs_wc_redirect');
function fs_wc_redirect() {
    if ( ! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) {
        wp_redirect( home_url() );
See our featured website design work

Check out some of the beautiful websites we’ve built for over 2,000 clients.

We offer WordPress support & maintenance

Shake the stress of ongoing maintenance with plans supported by our team of WordPress experts.

Related articles