Last active
August 29, 2015 13:56
-
-
Save goliver79/8824095 to your computer and use it in GitHub Desktop.
[WOOCOMMERCE] Shop pages limited view
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
<?php | |
// only some users can view shop pages | |
add_action( 'template_redirect', 'check_user_view' ); | |
function check_user_view(){ | |
if( is_some_shop_page() ){ | |
// we are in some woocomerce (shop) page | |
if( !( user_can_view_shop() ) ){ | |
wp_redirect( get_home_url() ); | |
} | |
} | |
} | |
function is_some_shop_page(){ | |
if( is_woocommerce() || is_cart() || is_checkout() ){ | |
return true; | |
} | |
return false; | |
} | |
function user_can_view_shop(){ | |
// only registered users. | |
if ( is_user_logged_in() ){ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment