Last active
August 29, 2015 14:07
-
-
Save woogist/06ad160968503e157778 to your computer and use it in GitHub Desktop.
Hide a specific category from the shop
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
function wc_hide_category_archive() { | |
$hide_category = 'category-slug'; //Change this with your category slug | |
if ( ! is_user_logged_in() && is_product_category( $hide_category ) ) { | |
wp_redirect( home_url() ); | |
exit; | |
} elseif ( is_product() && ! is_user_logged_in() ) { | |
global $product; | |
$taxonomy = 'product_cat'; | |
$terms = get_the_terms( get_the_ID(), $taxonomy ); | |
if ( $terms && ! is_wp_error( $terms ) ) { | |
foreach ( $terms as $term ) { | |
if ( $term->slug == $hide_category ) { | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} | |
} | |
} | |
} | |
add_action( 'template_redirect', 'wc_hide_category_archive' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment