• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Logo

impressive pages: Webdesign und eCommerce

  • Home
  • Blog
  • Hosting
  • Contact
Start » Blog » Visually separate sub-categories of products in WooCommerce – separate ‘ul’ lists

Visually separate sub-categories of products in WooCommerce – separate ‘ul’ lists

22. December 2021 Leave a Comment

Visually separate sub-categories of products in WooCommerce

With WooCommerce, the sub-categories in front of the products are shown or hidden in the standard version on the category archive page, depending on the configuration. However, it is not possible to display the list separately. If we want to separate the representation and have two separate listings, it is possible to use the following code.

/**
* Move WooCommerce subcategory list items into their own <ul> separate from the product <ul>.
*/
add_action( 'init', 'iphf_move_subcat_list' );
function iphf_move_subcat_list() {
	// Remove the subcat <li>s from the old location.
	remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
	add_action( 'woocommerce_before_shop_loop', 'iphf_product_loop_start', 1 );
	add_action( 'woocommerce_before_shop_loop', 'iphf_maybe_show_product_subcategories', 2 );
	add_action( 'woocommerce_before_shop_loop', 'iphf_product_loop_end', 3 );
}
/**
 * Conditonally start the product loop with a <ul> contaner if subcats exist.
 */
function iphf_product_loop_start() {
	$subcategories = woocommerce_maybe_show_product_subcategories();
	if ( $subcategories ) {
		woocommerce_product_loop_start();
	}
}
/**
 * Print the subcat <li>s in our new location.
 */
function iphf_maybe_show_product_subcategories() {
	echo woocommerce_maybe_show_product_subcategories();
}
/**
 * Conditonally end the product loop with a </ul> if subcats exist.
 */
function iphf_product_loop_end() {
	$subcategories = woocommerce_maybe_show_product_subcategories();
	if ( $subcategories ) {
		woocommerce_product_loop_end();
	}
}

This is what it looks like in the frontend:

Move WooCommerce subcategory list items into their own separate from the product

Thus we are able to style the subcategories accordingly and display them as filters, for example. This enables customers to better find products from the catalog.

Thanks to twoelevenjay

Filed Under: WooCommerce, WordPress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search

Recent Posts

  • WooCommerce: Show free shipping only
  • Remove wrapper DIVs (.wrap) in Genesis
  • Remove the number of products in the category list from the category name
  • Change the number of similar products in WooCommerce
  • Genesis Visual Hook Guide

Categories

  • development
  • Genesis framework
  • Google Search Console
  • mobile
  • SEO
  • Uncategorized
  • Web hosting
  • WooCommerce
  • WordPress

Archives

  • May 2022
  • January 2022
  • December 2021
  • imprint
  • Data protection

Footer

!pages
Heinrich Franz
Wilhelm-Martin-Str. 4
76356 Weingarten (Baden)
instagram
+49 160 85 40 725
info@impressive-pages.de

In my Blog I publish articles about WordPress, Genesis framework und SEO.

© 2022 impressive pages

  • Deutsch