Hide WooCommerce Products & Pages For Logged Out Users

WooCommerce

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() );
        exit;
    }
}
Menu
Google Rating
5.0
Based on 240 reviews
Get a Quote