css - 将属性文本转换为在 WooCommerce 变体选择中大写

标签 css woocommerce attributes hook-woocommerce product-variations

我使用 CSS 隐藏了变体框的标签,并向包含属性名称的选择框添加了自定义文本。这是我使用的代码:

function filter_woocommerce_dropdown_variation_attribute_options_args( $array ) { 

    $attribute_name = wc_attribute_label($array['attribute']);
    $select_text = 'Choose an ' . $attribute_name;

    $array['show_option_none'] = __( $select_text, 'woocommerce' );
    return $array; 
}; 

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_woocommerce_dropdown_variation_attribute_options_args', 10, 1 ); 

隐藏标签的CSS:

.variations th.label {
  display: none;
}

现在我只想让这句话变得可用,但我找不到合适的CSS。我几乎确定我需要使用 text-transform: capatilize 但我不确定在哪里添加它,最重要的是使用哪个 css class/id。我可以将其添加到代码片段中吗?

我在这里尝试了类似问题的一些答案,但它们都不起作用。

感谢任何帮助。

最佳答案

function filter_woocommerce_dropdown_variation_attribute_options_args( $array ) { 

    $attribute_name = wc_attribute_label($array['attribute']);
    $select_text = ucwords( 'Choose an ' . $attribute_name );
    

    $array['show_option_none'] = __( $select_text, 'woocommerce' );
    return $array; 
}; 

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_woocommerce_dropdown_variation_attribute_options_args', 10, 1 ); 

请检查将字符串大小写更改为 upper 的链接, lower , capitalize ...

关于css - 将属性文本转换为在 WooCommerce 变体选择中大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74373565/

相关文章:

jquery - 使用 sprite 的平滑 CSS 动画

css - 'react-scripts' 构建在 CSS 中嵌入一些图像作为数据 uri

mysql - 获取 WooCommerce 中没有特定分类的产品列表

wordpress - 如何获得woocommerce中最受欢迎产品的类别列表

c++ - 功能模板的部分属性在 GCC 中被静默忽略

PHP破坏CSS布局

css - 在复杂多边形上使用图像映射的替代方法

css - 产品页面 woocommerce 上的文件图标不会消失

html - CSS :not() with [attribute*=value] selector not works properly

javascript - http javaScript 将属性默认设置为所有标签