WC_Email::format_string( mixed $string )
Format email string.
Description Description
Parameters Parameters
- $string
-
(Required) Text to replace placeholders in.
Return Return
(string)
Source Source
File: includes/emails/class-wc-email.php
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 );
}