最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Conditional for product attribute page

programmeradmin4浏览0评论

Setup - the WooCommerce main "Shop" page with a "Filter Products By Attribute" () sidebar widget.

When I select an attribute, the page displays products accordingly (/shop/?filter_name=filter_type).

i want a check for when the page is showing a filtered list of products, i.e.

if (shop_page_is_showing_filtered())

// 

elseif (is_shop())

// 

Something like this is good - Show attribute description when filtering by that attribute - but it requires explicitly stating the attribute. I just want to know if my page is showing ANY attribute.

Thanks!

Setup - the WooCommerce main "Shop" page with a "Filter Products By Attribute" (https://docs.woocommerce/document/woocommerce-widgets/#section-6) sidebar widget.

When I select an attribute, the page displays products accordingly (/shop/?filter_name=filter_type).

i want a check for when the page is showing a filtered list of products, i.e.

if (shop_page_is_showing_filtered())

// 

elseif (is_shop())

// 

Something like this is good - Show attribute description when filtering by that attribute - but it requires explicitly stating the attribute. I just want to know if my page is showing ANY attribute.

Thanks!

Share Improve this question asked May 6, 2020 at 9:40 David FlindallDavid Flindall 11
Add a comment  | 

1 Answer 1

Reset to default 0

This is the answer:

function active_woocommerce_filters() {

    // for older WC versions
    // global $_chosen_attributes;

    $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();

    return count( $_chosen_attributes );

}

https://stackoverflow/questions/33229238/woocommerce-check-if-filtering-products

发布评论

评论列表(0)

  1. 暂无评论