Customize WooCommerce Variation Dropdown Labels

The default label for variations dropdown boxes is ‘Choose an option’ which is fine if you’ve only got one but if you have several attributes it can be confusing and not especially user friendly. Using a little snippet of php (this snippet uses anonymous functions so you’ll need to be running php 7 or above) we can grab the name of the attribute and display that in the label instead. Check it out:

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', function ( $args ) {
    $attr = get_taxonomy( $args['attribute'] );
    $args['show_option_none'] = "Choose a " . $attr->labels->singular_name;
    return $args;
}, 10 );

Place the code above carefully in your functions.php file, at the bottom is fine, or at the top, doesn’t really matter so long as it’s not inside another bloc of code.
We’re adding a filter to the output of ‘woocommerce_dropdown_variation_attribute_options_args’ we’re getting the attribute information because it’s stored as a taxonomy in WP, then we’re updating the ‘show_option_none’ field to include the title of the attribute.

Let me know what you think!

Leave a Reply

Your email address will not be published. Required fields are marked *