• Resolved jasonluna

    (@jasonluna)


    I’m trying to display a custom field (a field that was created in Advanced Custom Fields)

    Currently I have this line in the custom template

    <?php if( get_field('wholesale_part_number') ): ?><dt class="pn"><?php the_field('wholesale_part_number'); ?></dt><dd class="pn"><?php the_field('wholesale_part_number'); ?></dd><?php endif; ?>
    

    The custom template is selected in general settings.

    Please advise – what am I doing wrong here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    You need to pass the product ID, because when not operating on the actual WooCommerce Product page, ACF wouldn’t know which product you want to query for the wholesale part number.
    Try this:

    
    <?php if( get_field('wholesale_part_number', $item['product_id'] ) ): ?><dt class="pn"><?php the_field('wholesale_part_number', $item['product_id']); ?></dt><dd class="pn"><?php the_field('wholesale_part_number', $item['product_id']); ?></dd><?php endif; ?>
    

    Note that you used the_field twice in your example, I think you will want to replace the first with a static text like “Wholesale part number”.

    Let me know if that indeed does the trick!

    Ewout

    Thread Starter jasonluna

    (@jasonluna)

    That worked amazingly! Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying Advanced Custom Fields in Custom Template’ is closed to new replies.