Change Text String Woocommerce (Best Solution)

After searching everywhere in the internet, I found the best solution to change text string in woocommerce. I found this in github at

https://gist.github.com/trys/c8325701fea44ba99fed

This is simple solution for minor text string changes. For more robust changes, it would be better to use translator tools.

/**
 * Change WooCommerce text strings.
 *
 * @param	string	$translated
 * @param	string	$text
 * @param	string	$domain
 * @return	string
 */
function projectnamespace_woocommerce_text( $translated, $text, $domain ) {
	if ( $domain === 'woocommerce' ) {
		$translated = str_replace(
			array( 'Apply Coupon', 'Update Basket', 'Coupon code', 'Free!' ),
			array( ''            , 'Update'       , 'Voucher'    , ''      ),
			$translated
		);
	}

	return $translated;
}

add_filter( 'gettext', 'projectnamespace_woocommerce_text', 30, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *