Answer the question
In order to leave comments, you need to log in
How to hide woocommerce subcategories?
How to hide subcategories in woocommerce? It is necessary that when switching to a category, its subcategories are not displayed. I changed the settings in woocommerce itself, but they do not work. Most likely they do not work due to the fact that there is a code for displaying categories above products (The code itself is below). Please tell me how to resolve the issue.
function tutsplus_product_subcategories( $args = array() ) {
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats-top">';
foreach ( $terms as $term ) {
echo '<li class="category-top-shop">';
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
woocommerce_subcategory_thumbnail( $term );
echo '<h3>'.$term->name.'</h3>';
echo '</a>';
}
echo '</ul>';
}
}
add_action( 'woocommerce_before_shop_loop', 'tutsplus_product_subcategories', 10 );
Answer the question
In order to leave comments, you need to log in
Found a solution.
By default, the store page uses the archive-product.php template file. We add our own template for this page, for example, shop.php:
add_filter( 'woocommerce_template_loader_files','add_shop_template_loader_files', 10, 1 );
function add_shop_template_loader_files($default_file){
if( is_shop()){
$default_file[] = WC()->template_path() .'shop.php';
}
return $default_file;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question