wc_get_product_taxonomy_class()WC 3.4.0

Get product taxonomy HTML classes.

Хуков нет.

Возвращает

Массив.

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

wc_get_product_taxonomy_class( $term_ids, $taxonomy );
$term_ids(массив) (обязательный)
Array of terms IDs or objects.
$taxonomy(строка) (обязательный)
Taxonomy.

Список изменений

С версии 3.4.0 Введена.

Код wc_get_product_taxonomy_class() WC 9.4.2

function wc_get_product_taxonomy_class( $term_ids, $taxonomy ) {
	$classes = array();

	foreach ( $term_ids as $term_id ) {
		$term = get_term( $term_id, $taxonomy );

		if ( empty( $term->slug ) ) {
			continue;
		}

		$term_class = sanitize_html_class( $term->slug, $term->term_id );
		if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
			$term_class = $term->term_id;
		}

		// 'post_tag' uses the 'tag' prefix for backward compatibility.
		if ( 'post_tag' === $taxonomy ) {
			$classes[] = 'tag-' . $term_class;
		} else {
			$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
		}
	}

	return $classes;
}