Display products and subcategories on separate rows on listings pages
-
Hi,
Woocommerce categories and products appear on the same row, in the same ul element. I personally find this confusing and was looking for a way to separate them.
I found this code, which looks like a very clean solution.
// Remove subcategories from the product loop remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' ); // Add subcategories before the product loop with priority 5 add_action( 'woocommerce_before_shop_loop', 'cg_show_product_subcategories', 5 ); function cg_show_product_subcategories() { $subcategories = woocommerce_maybe_show_product_subcategories(); if ( $subcategories ) { echo '<ul class="products subcategories">', $subcategories, '</ul>'; } }
Source: https://www.commercegurus.com/docs/shoptimizer-theme/products-subcategories-separate/
The listings pages look much better like this!
The problem is that on my site (I’m using the Astra free theme), the categories are now showing twice. In their new place (before the shop loop, just above the ordering filter options, which is actually perfect and should be their default place in my opinion), AND in the shop loop alongside with the products (the default place where they already were before).
Could someone help me find the way to prevent them to show a second time in the shop loop?
And what’s about make this a default behaviour (or at least an option) in Woocommerce?
- You must be logged in to reply to this topic.