Home » WooCommerce: Display Product Categories @ Shop

WooCommerce: Display Product Categories @ Shop

by Tutor Aspire

We already saw how to show product categories in the Cart, how to display a category in the Shop page, but we never talked about showing ALL the product’s categories in the Shop / Category / Tag / Loop pages.

On top of that, we’ll also study the wc_get_product_category_list() function again, which is a super useful shortcut to get all the categories for a given product. Enjoy!

In my test website, and specifically on the shop page, here’s the “after” once the snippet below is added to funcitons.php. A list of product categories links appear just above the Add to cart button.

PHP Snippet: Show Product Categories’ Links @ Shop Loop Item

 * @snippet       WooCommerce: Product Categories @ Shop Items
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com

add_action( 'woocommerce_after_shop_loop_item', 'tutoraspire_show_product_categories', 9 );

function tutoraspire_show_product_categories() {
global $product;
echo wc_get_product_category_list( $product->get_id(), ', ', '

', '

' ); }

You may also like