[英]woocommerce- How to only show subcategories on shop page?
Edit:Managed to limit subcategories to shop page by wrapping the code inside the function in if(is_shop())
.NOw my shop page has multiple print outs of all the subcategories, I want to limit it to ONE Print of all the categories possibly paginated. 编辑:通过将代码包装在
if(is_shop())
的函数内,可以将子类别限制为商店页面。现在我的商店页面具有所有子类别的多个打印输出,我希望将其限制为所有类别的一个打印分页。
I am trying to show Subcategories(or child categories)only on the shop page then once a subcategory is selected show the products within. 我试图仅在商店页面上显示子类别(或子类别),然后一旦选择了子类别,便显示其中的产品。 My code below shows the subcategories on the main shop page but once a subcategory is selected it still shows all subcategories above the products.
我下面的代码显示了商店主页面上的子类别,但是一旦选择了子类别,它仍然显示产品上方的所有子类别。 Any assistance would be appreciated.
任何援助将不胜感激。
function Only_show_Subcategories($args = array()){
$terms = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => true,
) );
if($terms){
echo '<ul class = "products product-grid gutters row clearfix columns-3">';
foreach ($terms as $term){
if($term->parent > 0){
echo '<li class="product-category product col-sm-4 first product-category product item-animated">';
echo'<a href="'. esc_url( get_term_link( $term)). '"class="'.$term->slug.'">';
woocommerce_subcategory_thumbnail( $term);
echo '</a>';
echo '<h2>';
echo'<a href="'. esc_url( get_term_link( $term)). '"class= product-details"'.$term->slug.'">';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
}
echo '</ul>';
}
}
add_action('woocommerce_shop_loop','Only_show_Subcategories', 30);
I had this issue as well and I solved it with a work around. 我也遇到了这个问题,并通过解决方法解决了这个问题。 I added the plugin called "Widgets On Pages" then I went to my widgets, added the woocommerce product categroies to it and selected to only show sub categories.
我添加了名为“页面上的窗口小部件”的插件,然后转到窗口小部件,向其中添加了woocommerce产品类别,并选择了仅显示子类别。 Then I made a new page and added the shortcode in it for the widgets on pages that I created and set my woocommerce shop page to that page.
然后,我创建了一个新页面,并在其中添加了我创建的页面上的小部件的简码,并将woocommerce商店页面设置为该页面。 Problem solved.
问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.