• lordanti

    (@lordanti)


    I’m developing my first WordPress/Woocommerce site, and I want to change some words in the default WordPress translation of the site, in order to better suit the type of business. Currently I’m using the following code on the functions.php file of my theme (a Storefront’s child theme):

    add_filter('gettext', 'noProducto');
    
    function noProducto($translated) {
    
        $default = array ('Descripción del producto', 'Productos relacionados');
        $desired = array ('Descripción del inmueble', 'Inmuebles similares');    
    
    $translated = str_ireplace($default, $desired , $translated);
    
    return $translated;
    }

    It works, but I have read that this is not very efficient and could lead to performance problems. I want to use the recommended method instead:

    function my_text_strings( $translated_text, $text, $domain ) {
    	switch ( $translated_text ) {
    		case 'Descripción del producto' :
    			$translated_text = __( 'Descripción del inmueble', 'woocommerce' );
    			break;
    		case 'Productos relacionados' :
    			$translated_text = __( 'Inmuebles similares', 'woocommerce' );
    			break;
    
    	}
    	return $translated_text;
    };
    add_filter( 'gettext', 'my_text_strings', 20, 3 );

    However, it does not work for me, and I don’t know why.
    I’m new to WordPress and I’m trying to learn good practices; so any hint on why the first method works on my site and the second one does not, will be very much appreciated.

  • The topic ‘Trying to change some default words and sentences’ is closed to new replies.