Skip to content

Instantly share code, notes, and snippets.

@wpflames
Last active February 9, 2022 20:10
Show Gist options
  • Select an option

  • Save wpflames/9716a80acc001576a031b3d012e840a1 to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/9716a80acc001576a031b3d012e840a1 to your computer and use it in GitHub Desktop.
How to display Categories and Products in Separate Lists in Woo
<?php // Don't copy the opening php tag
// =========================================================================
// SEPARATE PRODUCTS AND SUBCATEGORY ON ARCHIVE PAGES
// =========================================================================
function display_product_subcategories( $args = array() ) {
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats">';
foreach ( $terms as $term ) {
echo '<li class="category">';
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
woocommerce_subcategory_thumbnail( $term );
echo '<h2>';
echo $term->name;
echo '</h2>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
}
add_action( 'woocommerce_before_shop_loop', 'display_product_subcategories', 50 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment