在我的网站上,本应仅显示产品的“商店”页面首先显示所有类别,然后是产品。
我想从产品列表中删除类别。您可以在 http://thehonestpet.com/shop/
查看问题示例商店页面上显示为产品的类别:
请指教?
我没有在 WordPress 中找到任何设置来解决此问题。也许是 CSS 修复?
以下方法有效,但仅隐藏“商店”页面中的类别,而不是产品类别页面...想法?
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'bedding', 'feeders-bowls', 'accessories', 'food', 'treats' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
其他两个答案非常接近,只需要在最后添加一点:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40, 0 );
在 function.php 中添加此代码
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
WooCommerce 产品类别显示在产品页面底部的“添加到购物车”按钮下方。
您可以通过从主题functions.php中的产品摘要中删除woocommerce_template_single_meta操作来从布局中删除这些内容。
像这样:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
这将从布局中删除类别(又名产品元)。