Website Building » WooCommerce » How Do I Change the Selected Option Text in WooCommerce?

How Do I Change the Selected Option Text in WooCommerce?

Last updated on January 19, 2023 @ 3:39 pm

When you are using WooCommerce to sell products or services online, you may want to change the text that appears for the “selected” option in the dropdown menus. For example, if you are selling shirts in different sizes, the default selected text may say “Choose an option..”. However, you can change this to something more specific, such as “Please select a size”.

In order to change the selected option text in WooCommerce, you will need to edit the code in the functions.php file of your child theme. If you do not have a child theme, you can create one by following the instructions here. Once you have a child theme set up, open the functions.php file and paste the following code snippet:

PRO TIP: If you are not familiar with code or are not comfortable working with code, we recommend finding a WooCommerce expert to help you make changes to your site. Making changes to the selected option text can break your site if not done correctly.
function my_theme_slug_change_option_text( $translated_text, $text ) {

if ( $text === 'Select an option.' ) {
    $translated_text = __( 'Please select an option', 'my-theme-slug' );
} elseif ( $text === 'Add to cart' ) {
    $translated_text = __( 'Add to cart', 'my-theme-slug' );
}
 
return $translated_text;
}
add_filter( 'gettext', 'my_theme_slug_change_option_text', 20, 2 );

In the code snippet above, you will need to replace “my-theme-slug” with the actual slug of your theme. You can find this by going to Appearance > Themes > Theme Details.

Once you have done this, save your changes and refresh the page. The new text should now appear for the selected options!

Conclusion:

In order to change the selected option text in WooCommerce, you will need to edit the code in the functions.

Madison Geldart

Madison Geldart

Cloud infrastructure engineer and tech mess solver.