Skip to content

Instantly share code, notes, and snippets.

@ninjaval
Created January 29, 2018 18:13
Show Gist options
  • Save ninjaval/97f3f297086aac7cd435f05b1de5db7e to your computer and use it in GitHub Desktop.
Save ninjaval/97f3f297086aac7cd435f05b1de5db7e to your computer and use it in GitHub Desktop.
Hide WooCommerce Pages/Products to logged out users & redirect them to homepage.
// redirecting individual products to homepage for logged out users
add_action( 'template_redirect', 'fs_maintance_mode' );
function fs_maintance_mode() {
if ( is_singular( 'product' ) && !is_user_logged_in() ) {
wp_redirect( home_url() );
exit;
}
}
// 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