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;
}
}
Jon Fullerhttps://freshysites.com/team/#Jon-FullerJon is from the Binghamton, NY area and graduated from the School of Art and Design at Alfred University with a Bachelor of Fine Arts. Concentrated studies were in Graphic Design and Video. Jon has an appreciation of all aspects of art and design, and has an extensive background in both print media and web — with a thorough understanding of video and photography. Jon comes to FreshySites with 9 years of graphic design and web experience. He continues to make a habit of researching new tools and technologies to broaden his knowledge in the web development industry. He’s a tech junkie who has a passion for implementing new techniques and improving his surroundings. Outside of work, Jon also enjoys going on new adventures with his wife, exercising, and sipping on quality craft beer.