Created
August 8, 2019 14:44
-
-
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
This file contains 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
<?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