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() );

Need help?

Tell us about your project!

This field is for validation purposes and should be left unchanged.

Related articles