Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // insert category name(s) before product in shop loop
- // products can have none, one or many categories
- // code goes in functions.php for your child theme
- add_action('woocommerce_before_shop_loop_item', 'insert_cat_names');
- function insert_cat_names() {
- $terms = get_the_terms($product->ID, 'product_cat');
- $nr_terms = count($terms);
- if ($nr_terms == 1) {
- print '<p class="cat_names">Category: '.$terms[0]->name.'</p>';
- }
- if ($nr_terms > 1) {
- print '<p class="cat_names">Categories: ';
- $first = true;
- foreach ($terms as $term) {
- if ($first) {
- $first = false;
- } else {
- print ', ';
- }
- print $term->name;
- }
- print '</p>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement