WC_Email::format_string()publicWC 1.0

Format email string.

Метод класса: WC_Email{}

Возвращает

Строку.

Использование

$WC_Email = new WC_Email();
$WC_Email->format_string( $string );
$string(разное) (обязательный)
Text to replace placeholders in.

Код WC_Email::format_string() WC 8.7.0

public function format_string( $string ) {
	$find    = array_keys( $this->placeholders );
	$replace = array_values( $this->placeholders );

	// If using legacy find replace, add those to our find/replace arrays first. @todo deprecate in 4.0.0.
	$find    = array_merge( (array) $this->find, $find );
	$replace = array_merge( (array) $this->replace, $replace );

	// Take care of blogname which is no longer defined as a valid placeholder.
	$find[]    = '{blogname}';
	$replace[] = $this->get_blogname();

	// If using the older style filters for find and replace, ensure the array is associative and then pass through filters. @todo deprecate in 4.0.0.
	if ( has_filter( 'woocommerce_email_format_string_replace' ) || has_filter( 'woocommerce_email_format_string_find' ) ) {
		$legacy_find    = $this->find;
		$legacy_replace = $this->replace;

		foreach ( $this->placeholders as $find => $replace ) {
			$legacy_key                    = sanitize_title( str_replace( '_', '-', trim( $find, '{}' ) ) );
			$legacy_find[ $legacy_key ]    = $find;
			$legacy_replace[ $legacy_key ] = $replace;
		}

		$string = str_replace( apply_filters( 'woocommerce_email_format_string_find', $legacy_find, $this ), apply_filters( 'woocommerce_email_format_string_replace', $legacy_replace, $this ), $string );
	}

	/**
	 * Filter for main find/replace.
	 *
	 * @since 3.2.0
	 */
	return apply_filters( 'woocommerce_email_format_string', str_replace( $find, $replace, $string ), $this );
}