Home > Software design >  Transform attribute text to capatilize in WooCommerce variation select
Transform attribute text to capatilize in WooCommerce variation select

Time:11-09

I have hidden the label of the variation box with CSS and added a custom text to the select box containing the name of the attribute. This is the code I used for that:

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 for hiding the label:

.variations th.label {
  display: none;
}

Now I just want to make this sentence capatilized but I can't find the right css for this. I'm almost sure I need to use text-transform: capatilize but I'm not sure where to add it and most important with which css class/id. Can I add it to the snippet maybe?

I tried some answers from similar questions here but they all didn't work.

Any help is appreciated.

CodePudding user response:

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 ); 

Please check the links for changing the string case to upper, lower, capitalize...

  • Related