替换 WooCommerce 可变产品页面上的特定属性标签文本
Replace specific attribute label text on WooCommerce variable product pages
是否可以将“尺寸”和“颜色”产品属性上的标签文本更改为 WooCommerce 单变量产品页面上的其他内容?
我试过这个 css 代码:
.single-product table.variations td.label > label{
visibility: hidden;
}
.single-product table.variations td.label > label:after {
content: 'NEW NAME';
visibility: visible;
}
但是它改变了“颜色”和“尺寸”变化。
我如何将它们分开?
我要更改的标签是 pa_farge
:
Source code “Chrome Developer”
2021 年更新
相反,您可以使用以下 WooCommerce 专用过滤器挂钩来定位特定产品属性并更改其显示的标签名称,如下所示:
add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3 );
function custom_attribute_label( $label, $name, $product ) {
// For "pa_farge" attribute taxonomy on single product pages.
if( $name == 'pa_farge' && is_product() ) {
$label = __('NEW NAME', 'woocommerce');
}
return $label;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。
是否可以将“尺寸”和“颜色”产品属性上的标签文本更改为 WooCommerce 单变量产品页面上的其他内容?
我试过这个 css 代码:
.single-product table.variations td.label > label{
visibility: hidden;
}
.single-product table.variations td.label > label:after {
content: 'NEW NAME';
visibility: visible;
}
但是它改变了“颜色”和“尺寸”变化。 我如何将它们分开?
我要更改的标签是 pa_farge
:
Source code “Chrome Developer”
2021 年更新
相反,您可以使用以下 WooCommerce 专用过滤器挂钩来定位特定产品属性并更改其显示的标签名称,如下所示:
add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3 );
function custom_attribute_label( $label, $name, $product ) {
// For "pa_farge" attribute taxonomy on single product pages.
if( $name == 'pa_farge' && is_product() ) {
$label = __('NEW NAME', 'woocommerce');
}
return $label;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。