Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save erikyo/964c5b5a27afb81890f40d5a279a142b to your computer and use it in GitHub Desktop.

Select an option

Save erikyo/964c5b5a27afb81890f40d5a279a142b to your computer and use it in GitHub Desktop.
Adds some useful classes to the WooCommerce layered navigation widget. This makes it very easy to stylise attribute colours or anything that can be represented with an icon.
<?php
/**
* Adds some useful classes to the WooCommerce layered navigation widget.
* This makes it very easy to stylise attribute colours or anything that can be represented with an icon.
*
* @param string $term_html - the item html
* @param object $term - the item props
*
* @return string - the old html list content wrapped inside a div with as class term id, term name and taxonomy
*/
add_filter( 'woocommerce_layered_nav_term_html', 'my_layered_nav_html_filter', 10, 2 );
function my_layered_nav_html_filter( $term_html, $term ){
return sprintf('<div class="%s %s %s">%s</div>',
"term-".$term->term_id,
"term-".$term->slug,
"tax-".$term->taxonomy,
$term_html
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment