Automattic\WooCommerce\Blocks\BlockTypes

ProductSummary::count_text()privateWC 1.0

Count words, characters (excluding spaces), or characters (including spaces).

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

Хуков нет.

Возвращает

int. Count of specified type.

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

// private - только в коде основоного (родительского) класса
$result = $this->count_text( $text, $count_type );
$text(строка) (обязательный)
Text to count.
$count_type(строка) (обязательный)
Count type: 'words', 'characters_excluding_spaces', or 'characters_including_spaces'.

Код ProductSummary::count_text() WC 9.7.1

private function count_text( $text, $count_type ) {
	switch ( $count_type ) {
		case 'characters_excluding_spaces':
			return strlen( preg_replace( '/\s+/', '', $text ) );
		case 'characters_including_spaces':
			return strlen( $text );
		case 'words':
		default:
			return str_word_count( wp_strip_all_tags( $text ) );
	}
}