Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created December 20, 2022 09:50
Show Gist options
  • Save elias1435/e2e0971613b9b3ec00a2a3d0015ab4ca to your computer and use it in GitHub Desktop.
Save elias1435/e2e0971613b9b3ec00a2a3d0015ab4ca to your computer and use it in GitHub Desktop.
Change ‘Choose an Option’ variation dropdown label in WooCommerce. Code goes in function.php file of your active child theme (or active theme).
/* OR you can use singular_name instead of name like: */
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_dropdown_variation_args', 10 );
function filter_dropdown_variation_args( $args ) {
$args['show_option_none'] = apply_filters( 'the_title', get_taxonomy( $args['attribute'] )->labels->singular_name );
return $args;
}
/* You can use wc_attribute_label() dedicated function to get the product attribute label name. */
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_dropdown_variation_args', 10 );
function filter_dropdown_variation_args( $args ) {
$args['show_option_none'] = apply_filters( 'the_title', wc_attribute_label( $args['attribute'] ) );
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment