如何移除Woocommerce变体属性标签中的冒号:
WooCommerce移除单商品页变体属性标签末尾冒号方案
你可以直接使用以下完整代码,添加到当前主题的functions.php文件或者自定义代码片段插件中即可生效:
add_filter( 'woocommerce_attribute_label', 'custom_remove_attribute_label_colon', 10, 3 ); function custom_remove_attribute_label_colon( $label, $name, $product ) { // 仅限制单商品页面生效,不影响其他页面属性标签展示 if ( is_product() ) { $label = rtrim( $label, ': ' ); } return $label; }
- 若需要全局移除所有页面的属性标签冒号,删除代码中的
if ( is_product() )判断条件即可 - 代码添加后若不生效,清理网站缓存、浏览器缓存后再刷新测试即可
- 如果主题自定义了WooCommerce属性渲染逻辑,可使用CSS方案兜底:
/* 将下方选择器替换为你实际页面变体标签的CSS选择器 */ .single-product .variations label::after { content: none !important; }
内容的提问来源于stack exchange,提问作者berrytea
相关产品推荐
相关产品推荐

