Is there a way to show per selected filter a specific description above the catalog in wooncommerce

Viewed 10

I am building a webshop with WooCommerce and want to show the selected filter description, as sample:

If selected filter 'color' than show the description above the catalog. BUT if you select 'size' than show only the description from the selected size as sample; selected filters: color, size, length, type, material. than only show the description from material.

this code below is working fine but only for one filter, not for all/multiple, how can i set multiple filters? like pa_brand and pa_size and pa_color etc. and then also showing always the last selected one.

already thanks!

add_action( 'woocommerce_before_shop_loop', 'desc_before', 75 ); function desc_before() {
if (is_filtered()) { 
    $brands = WC_Query::get_layered_nav_chosen_attributes() ['pa_brand'];
    if ( isset($brands) ) { 
        foreach ($brands['terms'] as $term ) {
            $term_obj  = get_term_by('slug', $term, 'pa_brand');

            echo '<div class="ka-attr-description">'.
                 '<h4>' . $term_obj ->name . '</h4>'.
                 $term_obj->description.
                 '</div>';
        } 
    }
}}
0 Answers
Related