php - WooCommerce - add custom class to variation option from dropdown select list

I try do add custom class to the variations select list. I know how to add class to the SELECT tag, but I can't traget each option from this list. I need to add custom class to the option tags.
here is my function:
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'my_dropdown_choice' );
/**
* Add class to option from variation list
*/
function my_dropdown_choice( $add_class ){
if( is_product() ) {
$add_class['class'] = 'my_custom_class';
}
return $add_class;
}
How to do it?
Answer
Solution:
WooCommerce has no hook that allows you to value the class attribute for each option of the product variations form but as you say it values the class attribute only for theselect
element.
To do this you will need to create a custom variation form using the woocommerce_dropdown_variation_attribute_options_html
hook.
WooCommerce Code Reference: woocommerce_dropdown_variation_attribute_options_html
You can find an example here:
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: 403 this action is unauthorized.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.