wc_get_product_taxonomy_class( array $term_ids, string $taxonomy )
Get product taxonomy HTML classes.
Description Description
Parameters Parameters
- $term_ids
-
(Required) Array of terms IDs or objects.
- $taxonomy
-
(Required) Taxonomy.
Return Return
(array)
Source Source
File: includes/wc-template-functions.php
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;
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |