Home › Forums › Support › Woocommerce / Display all Category Names for one Product This topic has 3 replies, 2 voices, and was last updated 3 years, 4 months ago by David. Viewing 4 posts - 1 through 4 (of 4 total) Author Posts November 22, 2022 at 7:27 am #2427251 Magnus Hello, I use this code <?php $terms = get_the_terms( get_the_ID(), 'product_cat' ); if ( $terms && ! is_wp_error( $terms ) ) : if ( ! empty( $terms ) ) { echo $terms[0]->name; }?> <?php endif;?> to show the category of a product. But it only shows one category of each product. But some products have more than one category. How must the code be modified to show all selected categories of each product? Thank you, Magnus November 22, 2022 at 8:36 am #2427555 DavidStaff Customer Support Hi there, you can try: <?php $terms = get_the_terms( get_the_ID(), 'product_cat' ); if ( $terms && ! is_wp_error( $terms ) ) { foreach ($terms as $term) { echo $term->name; } } ?> November 22, 2022 at 10:33 am #2427756 Magnus Hi David, works perfect 🙂 If seperator needed here is the code for this <?php $terms = get_the_terms( get_the_ID(), 'product_cat' ); if ( $terms && ! is_wp_error( $terms ) ) { $output = array(); foreach ($terms as $term) { $output[] = $term->name; unset($term); } echo implode(" | ", $output); } ?> November 23, 2022 at 2:43 am #2428648 DavidStaff Customer Support Glad to be of help and thanks for sharing your final version 🙂 Author Posts Viewing 4 posts - 1 through 4 (of 4 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In