Modify Text in a WordPress Plugin or Theme

PHOTO EMBED

Sat Apr 16 2022 08:01:47 GMT+0000 (Coordinated Universal Time)

Saved by @netropol #php

// Change string __( 'cart', 'woocommerce' )
add_filter( 'gettext', 'snippetpress_change_text', 10, 3 );
 
function snippetpress_change_text( $translation, $text, $domain ) {
    if ( $domain == 'woocommerce' ) { // Replace woocommerce with the text domain of your plugin
        if ( $text == 'cart' ) { // Replace cart with the word you want to change
            $translation = 'basket'; // Replace basket with your new word
        }
    }
}

//Change string with context _x( 'On hold', 'Order status', 'woocommerce' )
add_filter( 'gettext_with_context', 'snippetpress_change_text_with_context', 10, 4 );
 
function snippetpress_change_text_with_context ( $translation, $text, $context, $domain ) {
    if ( $domain == 'woocommerce' ) {
        if ( $text == 'On hold' && $context =='Order status' ) {
            $translation = 'Order received';
        }
    }   
    return $translation;
}
content_copyCOPY

https://snippetpress.com/how-to-modify-wordpress-text-strings-without-a-plugin/