1

Im trying to display the slug instead of the name of on a product single meta. This is the code which is displaying the current category name with a link to the category. Id like to do the same but use the slug as instead :

<?php        

global $post, $product;

    $cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );

    ?>
    <div class="product_meta">

        <?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Location:', 'Locations:', $cat_counts, 'woocommerce' ) . ' ', '</span>' ); ?>

        <?php do_action( 'woocommerce_product_meta_end' ); ?>

    </div>

Thank you

1 Answer 1

1

From your code, it looks like product_cat is a custom taxonomy. get_the_terms returns an array you can get the slug from. For instance...

$terms_array = get_the_terms($post->ID, 'procuct_cat');
$term_slug = $terms_array['your index']->slug;
2
  • Thanks, could you give an example of where that code should be placed in my example ? The code is from Woocommerce single product meta
    – Randomer11
    Commented Mar 1, 2017 at 15:23
  • Sorry. I can't help there. I haven't been working with woocommerce. It just so happens I was working on a custom plugin that needs the above functionality. If I had to guess, you could save the $term_slug variable and then echo it out or concatenate it to another string. Sorry I can't be more helpful than that!
    – aberkow
    Commented Mar 1, 2017 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.