You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WordPress中将WooCommerce商品分类分隔符从逗号改连字符?

修改WooCommerce商品分类分隔符为连字符

WooCommerce后台确实没有直接修改商品分类分隔符的选项,需要通过添加代码来实现需求。你可以将以下代码添加到当前主题的functions.php文件中,或者使用自定义代码插件(如Code Snippets)来导入:

add_filter( 'woocommerce_product_get_categories', 'replace_category_comma_with_dash', 10, 2 );
function replace_category_comma_with_dash( $categories, $product ) {
    // 将逗号分隔替换为指定的连字符(示例中的长破折号)
    return str_replace( ', ', ' – ', $categories );
}

这段代码会过滤商品分类的输出内容,把默认的逗号加空格分隔符替换成你需要的–(长破折号加空格)样式。如果需要调整分隔符的样式,直接修改代码里的' – '部分即可。

内容的提问来源于stack exchange,提问作者Camila Velez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 04:37:00