0

I’m setting up a woocommerce shop for my wife. In this shop, the brands mean a lot to us so we’ve added descriptions for each brand. A nice little story with an image and everything. Now when I click the brand-attribute from a single product page, I go to http://www.webshop.com/brand/brand-attribute which show the description above some products.

Is there a way to make this work with filters as well? So I’m in the shop and when I filter on brand X, that the description of brand X will appear on the page?

Thanks in advance

bumped to the homepage by Community 3 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You need to check when filter is enabled and take selected attribute taxonomy, 'pa_brand' in this case:

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>';
            } 
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.