0
votes

I created custom taxonomy for woocommerce products 'coffee_type'. I created an ACF image field 'coffee_type_image' to this taxonomy.

I want to show the image with a link and not the name of the taxonomy on the product page. I've read most articles here about showing acf image on taxonomy but every one of them is about working with the archive taxonomy page and not a product page. I'm editing the single-product.php (content-single-prodct.php to be exact).

This is my current loop

<?php $wcatTerms = get_terms('coffee_type', array('hide_empty' => 0, 'parent' => 0));
foreach ($wcatTerms as $wcatTerm):
?>
<ul>
   <li>
      <a href="<?php echo get_term_link($wcatTerm->slug, $wcatTerm->taxonomy); ?>"><?php echo $wcatTerm->name; ?></a>
        <?php $taxonomy = $queried_object->taxonomy;?>
   </li>
</ul>
<?php
endforeach;
?>

This is the var_dump of #wcatTerm

object(WP_Term)[3704]
  public 'term_id' => int 33
  public 'name' => string 'coffee and chicory' (length=18)
  public 'slug' => string 'coffee-and-chicory' (length=18)
  public 'term_group' => int 0
  public 'term_taxonomy_id' => int 33
  public 'taxonomy' => string 'coffee_type' (length=11)
  public 'description' => string '' (length=0)
  public 'parent' => int 0
  public 'count' => int 2
  public 'filter' => string 'raw' (length=3)

This is the var_dump of get_queried_object();

object(WP_Post)[3316]
  public 'ID' => int 671
  public 'post_author' => string '1' (length=1)
  public 'post_date' => string '2021-07-27 14:04:09' (length=19)
  public 'post_date_gmt' => string '2021-07-27 14:04:09' (length=19)
  public 'post_content' => string '<!--(figmeta)eyJmaWxlS2V5IjoiOWxOQjFWT01TaWFzVmx6cmxTUTl3YiIsInBhc3RlSUQiOjE2MjEzNjQ4LCJkYXRhVHlwZSI6InNjZW5lIn0K(/figmeta)--><!--(figma)ZmlnLWtpd2kEAAAARCMAALV7f5wsS1VfVc/M/rh7730/eTyeiIiIiKjvF+89EJGenp7dvjsz3a+7Z/beJzL0zvTuzruzM8P0zN67T0REQgxBRFQgiAQJUUSjqPgrQUVi1CSKvxERFRGNMYlJzC9jjMn3W9W/5u59fvzH+/ncqVOnTp06deqcU6eqet8m23GSRIdxeDqLhbjlkut0+kFo+qHAv47bsPvWjtnZtgNUZTew/VLdUNR2pwG4EjjbHbMFqBqEV1o2gJoC+oFNXmuKVnHuB7uO1/ftlmuy53rHDZ3mlX6w43ZbjX7X2/bNBvtvpGC/4XZY38zqvt307WAHqHOBZXfsPtDeTv/Rru1fAXKrjPRtr0Xk+Yb'... (length=52896)
  public 'post_title' => string 'Product Name 1' (length=14)
  public 'post_excerpt' => string '<!--(figmeta)eyJmaWxlS2V5IjoiOWxOQjFWT01TaWFzVmx6cmxTUTl3YiIsInBhc3RlSUQiOjE2MjEzNjQ4LCJkYXRhVHlwZSI6InNjZW5lIn0K(/figmeta)--><!--(figma)ZmlnLWtpd2kEAAAARCMAALV7f5wsS1VfVc/M/rh7730/eTyeiIiIiKjvF+89EJGenp7dvjsz3a+7Z/beJzL0zvTuzruzM8P0zN67T0REQgxBRFQgiAQJUUSjqPgrQUVi1CSKvxERFRGNMYlJzC9jjMn3W9W/5u59fvzH+/ncqVOnTp06deqcU6eqet8m23GSRIdxeDqLhbjlkut0+kFo+qHAv47bsPvWjtnZtgNUZTew/VLdUNR2pwG4EjjbHbMFqBqEV1o2gJoC+oFNXmuKVnHuB7uO1/ftlmuy53rHDZ3mlX6w43ZbjX7X2/bNBvtvpGC/4XZY38zqvt307WAHqHOBZXfsPtDeTv/Rru1fAXKrjPRtr0Xk+Yb'... (length=22771)
  public 'post_status' => string 'publish' (length=7)
  public 'comment_status' => string 'open' (length=4)
  public 'ping_status' => string 'closed' (length=6)
  public 'post_password' => string '' (length=0)
  public 'post_name' => string 'product-name-1' (length=14)
  public 'to_ping' => string '' (length=0)
  public 'pinged' => string '' (length=0)
  public 'post_modified' => string '2021-07-31 11:57:41' (length=19)
  public 'post_modified_gmt' => string '2021-07-31 11:57:41' (length=19)
  public 'post_content_filtered' => string '' (length=0)
  public 'post_parent' => int 0
  public 'guid' => string 'http://localhost/orc/?post_type=product&p=671' (length=50)
  public 'menu_order' => int 0
  public 'post_type' => string 'product' (length=7)
  public 'post_mime_type' => string '' (length=0)
  public 'comment_count' => string '3' (length=1)
  public 'filter' => string 'raw' (length=3)

How can i display inside the ACF field 'coffee_type_image' with a link to the archive page? I don't know how to pass the ACF to this taxonomy to display the image with get_field();

I've tried things like

<?php $term = get_field('coffee_type_image', $wcatTerm->term_id);?>

and

<?php $term = get_field('coffee_type_image', $wcatTerm->term_id, $wcatTerm->taxonomy);?>

But they always return null Thank you

1

1 Answers

0
votes

I just found the answer to my question. Im posting if someone else needs this.

<?php $term = get_field('coffee_type_image', 'coffee_type_' . $wcatTerm->term_id);?>
 <a href="<?php echo get_term_link($wcatTerm->slug, $wcatTerm->taxonomy); ?>"><img src="<?php echo $term; ?>" alt="" class="img-responsive"></a>