68
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!
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://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(), ', ', '', '
' );
}