Skip to content

Instantly share code, notes, and snippets.

@goliver79
Last active August 29, 2015 13:56
Show Gist options
  • Save goliver79/8824095 to your computer and use it in GitHub Desktop.
Save goliver79/8824095 to your computer and use it in GitHub Desktop.
[WOOCOMMERCE] Shop pages limited view
<?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