Php WordPress中标签的过滤功能

Php WordPress中标签的过滤功能,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在开发一个使用WooCommerce的WordPress网站。WooCommerce将产品属性标签中的每个单词大写,这会影响长标签的可读性 function wc_attribute_label( $name, $product = '' ) { global $wpdb; if ( taxonomy_is_product_attribute( $name ) ) { $name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '',

我正在开发一个使用WooCommerce的WordPress网站。WooCommerce将产品属性标签中的每个单词大写,这会影响长标签的可读性

function wc_attribute_label( $name, $product = '' ) {
global $wpdb;
if ( taxonomy_is_product_attribute( $name ) ) {
    $name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
    $label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
if ( ! $label ) {
    $label = ucfirst( $name );
    }
} elseif ( $product && ( $attributes = $product->get_attributes() ) && isset( $attributes[ sanitize_title( $name ) ]['name'] ) ) {
    // Attempt to get label from product, as entered by the user
    $label = $attributes[ sanitize_title( $name ) ]['name'];
} else {
    // Just format as best as we can
    $label = ucwords( str_replace( '-', ' ', $name ) );
}

return apply_filters( 'woocommerce_attribute_label', $label, $name, $product ); }
我需要将上述代码片段中的“ucwords”更改为“ucfirst”:

$label = ucwords( str_replace( '-', ' ', $name ) );
我想在functions.php文件中为此创建一个过滤器。看起来应该很容易,但我有很多困难。任何帮助都将不胜感激。这就是我所拥有的:

add_filter( 'woocommerce_attribute_label' , 'custom_attribute_label' );
function custom_attribute_label( $label ) {
$label = ucfirst ( $label );
return ( $label ); }

问题在于add_过滤器的语法

已更正代码。请立即尝试此代码,如果有帮助,请告诉我

add_filter( 'woocommerce_attribute_label' , 'custom_attribute_label',99,3 );

function custom_attribute_label( $label, $name, $product ) {
  $label = ucfirst ( $label );
  return ( $label ); 
}

问题在于add_过滤器的语法

已更正代码。请立即尝试此代码,如果有帮助,请告诉我

add_filter( 'woocommerce_attribute_label' , 'custom_attribute_label',99,3 );

function custom_attribute_label( $label, $name, $product ) {
  $label = ucfirst ( $label );
  return ( $label ); 
}

这实际上不起作用,但我真的很感谢你的回答。它激励我学习更多关于过滤器的知识。我最后安装了一个插件,因为我需要在我的WooCommerce订单中添加额外的功能。插件碰巧解决了标签问题。再次,非常感谢。这实际上不起作用,但我真的很感谢你的回答。它激励我学习更多关于过滤器的知识。我最后安装了一个插件,因为我需要在我的WooCommerce订单中添加额外的功能。插件碰巧解决了标签问题。再次感谢大家。