0
votes

I am currently using ACF 5. I have set up a repeater on the product categories.

I'm currently struggling with how to get it to output the information. I am inside the acrhive-product loop and I am updating the following template that contains the content that gets outputting:

<?php while ( have_posts() ) : the_post(); ?>

    <?php wc_get_template_part( 'content', 'product_cat' ); ?>

<?php endwhile; // end of the loop. ?>

In content-product_cat.php I have the following for each loop for the repeater. All the basic information already shows, the title, the woocommerce category image etc. Its the repeater I added to the categories themselves I can't get to show.

<?php
    $terms = get_field('attributes', 'product_cat_'.$term->term_id); 
    if($terms): ?>
        <ul>
    <?php foreach( $terms as $term ): ?>
            <li>
             <?php the_sub_field('attribute'); ?>
            </li>
    <?php endforeach; ?>
        </ul>
      <?php endif; ?>

Any thoughts would be greatly appreciated

1
Do you have WP_DEBUG enabled? You might want to. That might tell you, at least, if you have undefined objects/variables. How are you defining $term->term_id? I'd start there because without term you'll never even get into the foreach() loop. After that, I don't know enough about ACF.helgatheviking

1 Answers

0
votes

Printed out the args first:

<?php print_r($category);?>

Then used its output to produce the following:

<?php 
        $cat_id = $category->term_id; //used below to get a the acf from the categories!
    ?>


<?php
        // $cat_id = $category->term_id;

        $terms_features = get_field('features', 'product_cat_'.$cat_id); 
        if($terms_features): 
            // print_r($terms_features); 
        ?>
        <ul>
        <?php foreach( $terms_features as $terms_feature ): 
        // print_r($term); 
        ?>
        <?php
          $image_icon = $terms_feature['icon'];
          $image_icon_show = $image_icon[sizes][large];
          // print_r($image_feature);
        ?>
                <li>
                    <img src="<?php echo $image_icon_show;?>" />
                    <?php echo $terms_feature['description'];?>
                </li>
         <?php endforeach; ?>
        </ul>
      <?php endif; ?>