【问题标题】:How to modify and style WooCommerce product category count NUMBER in sidebar widget如何在侧边栏小部件中修改和设置 WooCommerce 产品类别计数 NUMBER
【发布时间】:2020-05-07 08:44:03
【问题描述】:

好的,所以我找到了修改主页中类别计数的“woocommerce_subcategory_count_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;
}

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


我们在每个类别的右侧都有类别和计数。 我想删除括号并设置计数的样式。

我已经尝试在网上抓取示例,但我找不到任何特定于侧边栏类别列表的内容。

这可能吗?

如果有人对我可以找到解决此特定问题的解决方案有任何想法,我们将不胜感激。

谢谢。

【问题讨论】:

    标签: php css wordpress woocommerce


    【解决方案1】:

    您可以在主题文件夹中的 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);
    }
    

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

    【讨论】:

    • 啊,太好了。我现在刚刚在 WP Codex 中查看了这个钩子,尽管我不知道如何做到这一点。这是在functions.php中正确过滤此列表的唯一方法吗?非常感谢,你让我很开心!
    • 好的,所以这与 WordPress 相比 WooCommerce 更具体。
    • Woocommerce 使用wp-content/plugins/woocommerce/includes/walkers/class-wc-product-cat-list-walker.php 呈现产品猫列表。我发现只有这种方式可以改变输出。另一种方法是使用 javascript 编辑 html
    • Vkuter,我从一个类似的早期问题中找到了一个类似的例子,它做同样的事情,但代码更少:wordpress.stackexchange.com/questions/88545/… 我不知道哪个更好/更有效?我很喜欢 php :/
    猜你喜欢
    • 2019-09-04
    • 2018-11-12
    • 2021-10-07
    • 2018-08-18
    • 2021-04-19
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多