简体   繁体   English

隐藏woocommerce商店中产品的一些类别名称

[英]hide some category names from products in woocommerce shop

I'd like to show some category names in the products description in my woocommerce shop page. 我想在woocommerce商店页面的产品描述中显示一些类别名称。 With this code below, I'm able to show all the categories, but what I need is to show only some category names . 通过下面的代码,我可以显示所有类别,但是我只需要显示一些类别名称

function wc_category_title_archive_products(){

$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );

if ( $product_cats && ! is_wp_error ( $product_cats ) ){

    $single_cat = array_shift( $product_cats ); ?>

    <span class="categoria"><?php echo $single_cat->name; ?></span>

Is it possible to exclude some category names or show just the ones I need? 是否可以排除某些类别名称或仅显示我需要的名称? thank you 谢谢

WooCommerce provides some coarse control over displaying sub categories in your shop/category pages with the “Show subcategories on category pages” and “Show subcategories on the shop page” options on the WooCommerce > Settings > Catalog > Catalog Options section. WooCommerce通过“ WooCommerce > Settings > Catalog > Catalog Options部分中的“在类别页面上显示子类别”和“在商店页面上显示子类别”选项,对在商店/类别页面中显示子类别提供了一些粗略的控制。

These controls are all-or-nothing though: show all subcategories on the category pages, or show all subcategories on the shop page. 这些控件是全有还是全无:在类别页面上显示所有子类别,或在商店页面上显示所有子类别。 If you want finer-grained control, for instance displaying only certain subcategories on the shop or particular subcategories on a given category catalog page, you'll need to write a little custom code, and there are a couple of approaches you can take. 如果要进行更细粒度的控制(例如,仅在商店中显示某些子类别,或在给定类别目录页面上仅显示特定子类别),则需要编写一些自定义代码,并且可以采用两种方法。

The existing limited controls, found in WooCommerce > Settings > Catalog, which allow you to hide all or none of the subcategories. 现有的有限控件位于WooCommerce>设置>目录中,可用于隐藏所有子类别或不隐藏任何子类别。

I recommend asking at https://wordpress.org/support/plugin/woocommerce#postform so the plugin's developers and support community can help you with this. 我建议在https://wordpress.org/support/plugin/woocommerce#postform进行询问,以便插件的开发人员和支持社区可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM