skip to Main Content

I would need to change "Please select an option." text on the woocommerce product page. Please check screenshots below, so you can see what I am talking about.

Preview of the error message:
code
interface

I tried to use the following code, but it didnt do anything after I added it to functions.php file.

function translate_error_message($translated_text, $text, $domain) {
    if ($translated_text == 'Please select an option.') {
        $translated_text = 'Vyberte jednu z možností.';
    }
    return $translated_text;
}
add_filter('gettext', 'translate_error_message', 20, 3);

2

Answers


  1. The HTML code is generated by javascript file "wpo-single-product.js" loaded by plugin "woocommerce-product-options". I couldn’t find public documentation for this plugin so you have two options:

    1. Review plugin source code to find any possible filter wich may allow to modify the string, it might be using "wp_localize_script" function.

    2. Contact directly plugin author for the guidance how to translate the string.

    Login or Signup to reply.
  2. Please try this code:

    //Change the Translate Text//
    function change_translated_text( $translated_text, $text, $domain ) {
        switch ( $translated_text ) {
            case 'Please select an option.':
                $translated_text = __( Vyberte jednu z možností.', 'your-text-domain' );
                break;
        }
        return $translated_text;
    }
    add_filter( 'gettext', 'change_translated_text', 20, 3 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search