Skip to content

Instantly share code, notes, and snippets.

@woogist
Last active August 29, 2015 14:07
Show Gist options
  • Save woogist/06ad160968503e157778 to your computer and use it in GitHub Desktop.
Save woogist/06ad160968503e157778 to your computer and use it in GitHub Desktop.
Hide a specific category from the shop
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