Show Woocommerce Product Categories in a List

In this post we will show you how you can add the Woocommerce product categories anywhere on the Woocommerce pages and not in the default sidebar. The categories will be displayed in a list. in our example, we will add the categories on the top of the Shop Page after the breadcrumb links.

 

This is how the Shop Page looks like before changing the code:

Show Woocommerce Product Categories in a List

 

You can add the categories by adding the following code to your functions.php file:

function arrowDesign_showProduct_categoriesInAList(){

$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);

$product_categories = get_terms( 'product_cat', $args );

$count = count($product_categories);
if ( $count > 0 ){
echo "<ul>";
foreach ( $product_categories as $product_category ) {
echo '<li><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</li>';

}//end for each category found
echo "</ul>";
}//end if count>0

}//end function arrowDesign_showProduct_categoriesInAList

/////testing function by displaying on on the product page, using 'woocommerce_before_main_content' hook
//
add_action( 'woocommerce_before_main_content', 'arrowDesign_showProduct_categoriesInAList', 20, 0 );
//
/////////end, testing function output, on product page

This is how the Shop Page looks like after changing the code:

Show Woocommerce Product Categories in a List

Conclusion

We hope this Show Woocommerce Product Categories in a List post was helpful and you are now able to integrate this also on your website! You can find more articles here:

 

Read another Woocommerce post : ‘Add a Custom Field to a Product Variation

 

Arrow Design, based in Dublin, Ireland, provides quality website design services in Dublin and beyond at affordable prices. If you would like help with implementing the above code, or any wordpress website development project, contact us. We love website design and it shows! We provide custom wordpress plugin development, website design training and lots more.

We do it all, so you don’t have to!

Related Posts

Woocommerce Account Page Hook Guide

In this article you will find a visual hook guide for the Woocommerce Account Pages, like the Login/Register page, the Downloads page or the Orders page.

Woocommerce PHP – Product Categories by Product ID

Woocommerce Single Product Page Hook Guide

In this article you will find a visual hook guide for the Woocommerce Single Product Page. This should help you to quickly and easily find the hook positions on the page.

Woocommerce PHP – Product Categories by Product ID

Woocommerce PHP – Product Categories by Product ID

In this tutorial you will learn how to check if a product is assigned to a tag, a category or a custom taxonomy. You can check if a product is is on the shop page, in the cart, in an order & more.

…We do more, so you can do less 🙂

 

Leave a message and we will be straight back to you!

Pin It on Pinterest

Share This