Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/8b3e7be6c35304aa7d9f4e40da685af5 to your computer and use it in GitHub Desktop.
Save Garconis/8b3e7be6c35304aa7d9f4e40da685af5 to your computer and use it in GitHub Desktop.
WooCommerce | Hide WooCommerce products and pages for logged-out users and redirect to homepage
<?php
// 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment