Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change or translate specific texts in Woocommerce

I found a solution online for this but it does not seem to work.

It says to edit the below file which I did a few days ago but somehow it is not working still.

/wp-content/plugins/woocommerce/templates/single-product/related.php

Which if I FTP to the server the file shows the below:

if ( $products->have_posts() ) : ?>

<div class="related products">

    <h2><?php _e('You may also like', 'woocommerce' ); ?></h2>

However the webpage still shows 'Related products' and not 'You may also like'

For some reason this is not taking place or being over ridden somewhere.

Any ideas?

like image 600
Mike Young Avatar asked Dec 02 '14 21:12

Mike Young


2 Answers

i found this for the child functions.php: http://speakinginbytes.com/2013/10/gettext-filter-wordpress/

/**
 * Change text strings
 *
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Related Products' :
            $translated_text = __( 'Check out these related products', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

it works well here: https://mo-sound.com/en/shop/ball-speaker-classic-white/

like image 63
user5217948 Avatar answered Sep 28 '22 04:09

user5217948


The best way to override default templates is to copy the file to a folder named /woocommerce/single-product inside your current theme. Make changes to that file.

In general to override Woocommerce template files like

/wp-content/plugins/woocommerce/templates/<foldername>/<filename>

you copy the file to

/wp-content/<your-theme>/woocommerce/<foldername>/<filename>

like image 40
RST Avatar answered Sep 28 '22 04:09

RST