-1

I added a custom taxonomy called "Topics" to woocomerce products and Now i would like to add an image to each Topic and have it shown on the page of that Topic.

I am trying to use Advanced Custom fields plugin but I do not know where to the the ACF php code.

Any help would be greatly appreciated.

lotto_guy
  • 37
  • 7

2 Answers2

0

Advanced Custom Fields Example Link Here https://www.advancedcustomfields.com/resources/code-examples/

get the ACF image filed in Taxonomy

    <?php
    $products_category_object       = get_queried_object();
    $product_category_taxonomy      = $products_category_object->taxonomy;
    $product_category_term_id       = $products_category_object->term_id;
    $category_acf_image = get_field('your ACF Image Field name', $product_category_taxonomy.'_'.$product_category_term_id);

    echo "<pre>";
    print_r($category_acf_image);
    echo "</pre>";
    ?>
    <img src="<?php echo $category_acf_image['your url key']; ?>" />
Shital Marakana
  • 2,817
  • 1
  • 9
  • 12
  • That part I already know. But in which wordpress/woocommerce file, and where in the file do I put it in? – lotto_guy Jul 27 '17 at 07:10
  • means product listing page or details page? – Shital Marakana Jul 27 '17 at 07:12
  • I want to add this custom image under the breadcrumbs of the "Topics" page, which is a product listing page. – lotto_guy Jul 27 '17 at 07:23
  • ok. copy "archive-product.php" file in this folder "wp-content\plugins\woocommerce\templates" and add in your current active them. You can edit your taxonomy page – Shital Marakana Jul 27 '17 at 07:33
  • Thanks, I am able to edit the category level pages but I need help setting it up with ACF. How do I make an image show up on taxonomy page? I am trying to use the first codes here https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/ of "display fields" but its not working out. – lotto_guy Jul 27 '17 at 08:08
  • what is your ACF Image field name? please check updated answer for get the ACF image filed in Taxonomy – Shital Marakana Jul 27 '17 at 08:16
  • OK i tried that, but now all I see is the default image icon and in inspect element is says – lotto_guy Jul 27 '17 at 08:49
  • ok. print_r($category_acf_image); check the url full path key and change the – Shital Marakana Jul 27 '17 at 08:57
  • someplaces i need to put the ['url']; and some places I dont. For Product categories I do, but for my custom taxonomy I dont. – lotto_guy Jul 27 '17 at 09:06
  • ok. now check and please give me your page website url. so i will check your url key. after then remove echo "
    ";
        print_r($category_acf_image);
        echo "
    "; code.
    – Shital Marakana Jul 27 '17 at 09:09
  • please find in your array. – Shital Marakana Jul 27 '17 at 09:33
0

There is a plugin Custom Category Image available in wordpress to do that. This plugin will add option to add image file for each category/taxonomy.

As specified in the plugin description use following code to get the image anywhere in your code -

MGC_Custom_Category_Image::get_category_image($term_id, $size);
Alice
  • 1,422
  • 1
  • 18
  • 30
  • I would rather not add a full new plugin if I can achieve it with what I already have. This is because I do not want my site to slow down. I already use ACF for other places on my site, so I'll use it here too. But thanks for answering. – lotto_guy Jul 28 '17 at 07:17