awf_display_filter_html

This hook allows the customization of HTML output of a single filter.

Hook type: filter

Parameters:

  1. The $display parameter can be returned as:
    • true – to continue the filter HTML generation
    • false – to abort the filter HTML generation
    • string containing some custom HTML that you would like to output in place of the current filter
  2. The $filter parameter allows the customization of the current instance of the filter class. The “terms” property of this instance (accessed as $filter->terms) contains the list of filtering options which you can modify as needed.

The following example applies numeric sorting to the options of the product width metadata-based filter:

function customize_width_filter_sorting( $display, $filter ) {

  if( 'meta' === $filter->module && '_width' === $filter->settings['meta_name'] ) {
    usort( $filter->terms, function( $a, $b ) {
      return (int) ( $a->slug > $b->slug );
    });
  }

  return $display;
}

add_filter( 'awf_display_filter_html', 'customize_width_filter_sorting', 10, 2 );