wc_get_product_taxonomy_class()
Get product taxonomy HTML classes.
No Hooks.
Returns
Array.
Usage
wc_get_product_taxonomy_class( $term_ids, $taxonomy );
- $term_ids(array) (required)
- Array of terms IDs or objects.
- $taxonomy(string) (required)
- Taxonomy.
Changelog
| Since 3.4.0 | Introduced. |
wc_get_product_taxonomy_class() wc get product taxonomy class code WC 10.8.1
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;
}