admin管理员组文章数量:1200344
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 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
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
Share Improve this question asked Dec 24, 2017 at 11:41 ErikErik 113 bronze badges1 Answer
Reset to default 1You 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>';
}
}
}
}
本文标签: customizationShow attribute description when filtering by that attribute
版权声明:本文标题:customization - Show attribute description when filtering by that attribute 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738592888a2101618.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论