Php script for updating text woocommerce

Viewed 72

I have this php script that updates my product titles:

add_filter( 'the_title', 'change_product_title', 10, 2 );
function change_product_title( $title, $id ) {
$Find = 'Mens Watch';
$ReplaceWith = 'Herreur';


//REMOVE DESIRED STRING FROM PRODUCT TITLE
$title = str_replace($Find, $ReplaceWith, $title);

return $title;
}

And it updates the title in every product title. But how can I make it so every word that has $find = ?? Gets replaced? And also, how can I add more words to the script so they also are replaced on my site?

Thanks!

1 Answers
add_filter( 'gettext', 'wp_custom_translate_text', 10, 3 );


function wp_custom_translate_text($translated_text, $untranslated_text, $domain) {

        $find = array("sample", "book");
        $replace = array("test");

        $translated_text = str_replace($find, $replace, $translated_text);
    
    return $translated_text;
}
Related