Php 如何在侧边栏小部件中修改和设置WooCommerce产品类别计数

Php 如何在侧边栏小部件中修改和设置WooCommerce产品类别计数,php,css,wordpress,woocommerce,Php,Css,Wordpress,Woocommerce,好的,我找到了一种方法来修改主页中的类别计数的“woocommerce\u subcategory\u count\u html”,就像functions.php中的那样,并在css中设置样式。下面是一张图片来说明我的意思: add_filter('woocommerce_subcategory_count_html', 'filter_woocommerce_subcategory_count_html', 10, 2); function filter_woocommerce_subcat

好的,我找到了一种方法来修改主页中的类别计数的“woocommerce\u subcategory\u count\u html”,就像functions.php中的那样,并在css中设置样式。下面是一张图片来说明我的意思:

add_filter('woocommerce_subcategory_count_html', 'filter_woocommerce_subcategory_count_html', 10, 2);

function filter_woocommerce_subcategory_count_html($mark_class_count, $category)
{
    $mark_class_count = ' <mark class="count">' . $category->count . '</mark>';
    return $mark_class_count;
}
add_filter('woocommerce_subcategory_count_html','filter_woocommerce_subcategory_count_html',10,2);
函数筛选器\u子类别\u计数\u html($mark\u class\u计数,$category)
{
$mark_class_count=''.$category->count';
返回$mark\u class\u count;
}

但是,我找不到一种方法来对产品页面侧栏中的产品类别计数进行相同的操作:


我们有分类和计数的权利,为每一个。 我想删除括号并设置计数编号的样式

例如,我曾尝试在网上爬行,但我找不到任何特定于侧边栏类别列表的内容

这可能吗

如果任何人有任何想法,我可以找到一个解决方案,以针对这一特定问题,它将不胜感激


谢谢。

您可以在主题文件夹的function.php文件中使用此挂钩

add_filter( 'wp_list_categories', 'update_count_output' );
function update_count_output($output) {
    return preg_replace('/\<span class\=\"count\"\>\((\d+)\)\<\/span\>/', '<span class="count">$1</span>', $output);
}
add_filter('wp_list_categories','update_count_output');
函数更新\计数\输出($output){
返回preg\u replace('/\\(\d+)\/'、'$1',$output);
}

然后您可以使用CSS设置计数的样式

Ahh,非常好。我现在只是在WP法典中寻找这个钩子,虽然我不知道如何在我的头顶上做到这一点。这是在functions.php中正确筛选此列表的唯一方法吗?非常感谢,你让我开心!好的,这对WordPress比WooCommerce更为具体。WooCommerce使用
wp-content/plugins/WooCommerce/includes/walkers/class-wc-product-cat-list-walker.php
呈现产品目录。我发现只有这种方法可以改变输出。另一种方法是使用javascriptVkuter编辑html,我在前面的一个类似问题中发现了一个类似的例子,它做了同样的事情,但代码更少:我不知道哪个更好/更高效?我对php非常熟悉:/