Using filters and translation to customize auto-ship text

Filters are available throughout WC Autoship so that store's can customize the term "Auto-Ship" throughout the website and email communications without making modifications to the plugin files directly.

To learn more about using filters to override and translate in Wordpress, check out this great doc  A Quick Introduction to Using Filters by Pippin Williamson.

In the example below, the WooCommerce store adds this code to their functions.php theme file in order to translate the default term "Auto-Ship" to "Auto-Replenish".  This translates every instance of this term on their website as well as their Autoship Schedule Email Template.

<?php

function wc_autoship_translate( $translated_text, $text, $domain ) {
	if ( strpos( $domain, 'wc-autoship' ) !== 0 ) {
		return $translated_text;
	}
	$find = array(
		'Auto-Ship',
		'auto-ship'
	);
	$replace = array(
		'Auto-Replenish',
		'auto-replenish'
	);
	$translation = str_replace( $find, $replace, $translated_text );
	return $translation;
}
add_filter( 'gettext', 'wc_autoship_translate', 10, 3 );

Still need help? Contact Us Contact Us