Created
January 29, 2018 18:13
-
-
Save ninjaval/97f3f297086aac7cd435f05b1de5db7e to your computer and use it in GitHub Desktop.
Hide WooCommerce Pages/Products to logged out users & redirect them to homepage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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