WooCommerce Link to Product Category

I’m creating a template for archive-product.php page in WooCommerce.

I would like to have 3 boxes and link each to a different product category.

How do I get dynamic link to each product category in <a> tag?
For now I put static links, but I’m sure there is a way to make them dynamic in WordPress

Here’s what my code looks like:

    <ul class="shop-items">
      <li class="fine-art">
        <a href="http://url.com/product-category/categories/fine-art/">
         <div>Fine Art
          <span>Description</span>
          </div>
        </a>
       </li>
       <li class="dance-art">
        <a href="http://url.com/product-category/categories/dance-art/">
         <div>Dance Art
          <span>Description</span>
          </div>
        </a>
       </li>
     <li class="history-art">
        <a href="http://url.com/product-category/categories/history-art/">
         <div>History Art
          <span>Description</span>
          </div>
        </a>
       </li>
 </ul>

2 Answers
2

For this purpose there is get_term_link function (documentation).

<a href="https://wordpress.stackexchange.com/questions/199226/<?php echo get_term_link( 42 ,"product_cat') ?>">Fine Art ... etc.</a>

Product category is just WP taxonomy, so there is plenty of functions to work with. In this case you have to know your product category ID (taxonomy term ID, actually). When editing category, you will find it in URL: …/edit-tags.php?action=edit&taxonomy=product_cat&tag_ID=42&post_type=product

Leave a Comment