admin管理员组文章数量:1326478
I want to target all pages (product categories) that are displaying the products themselves.
My woocommerce settings set to show only categories/subcategories (unless there are none) and then by default the products grid is displayed on the page.
is_product_category()
function doesn't help since it also targets the parent categories which don't have direct products in them.
Most of my categories that don't any subcategories in them are grandchildren categories if it matters for the answer.
How can I achieve it and to use it in woocommerce hooks?
I want to target all pages (product categories) that are displaying the products themselves.
My woocommerce settings set to show only categories/subcategories (unless there are none) and then by default the products grid is displayed on the page.
is_product_category()
function doesn't help since it also targets the parent categories which don't have direct products in them.
Most of my categories that don't any subcategories in them are grandchildren categories if it matters for the answer.
How can I achieve it and to use it in woocommerce hooks?
Share Improve this question asked Aug 6, 2020 at 10:48 VictorVictor 254 bronze badges1 Answer
Reset to default 0You can use the woocommerce_products_will_display()
. This function returns true
if the current shop page is going to display products. This will be the case if your shop pages are set to display products or subcategories and products, but it will be false
if the shop pages are set to display subcategories only, and the current category has subcategories.
if ( woocommerce_products_will_display() ) {
// Products are showing.
} else {
// Products are not showing.
}
The woocommerce_get_loop_display_mode()
is similar, but can let you know whether subcategories are also displaying:
switch ( woocommerce_get_loop_display_mode() ) {
case 'products':
// Products are displaying.
break;
case 'subcategories':
// Subcategories are displaying.
break;
case 'both':
// Products and subcategories are displaying.
break;
}
本文标签: How to target all woocommerce categories that don39t have any subcategories in them
版权声明:本文标题:How to target all woocommerce categories that don't have any subcategories in them? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742207711a2433127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论