Home Forums Front-end Issues ACF + Woocommerce Value Not Displaying


ACF + Woocommerce Value Not Displaying

  • Hi Guys, I’m trying to insert a custom field at the end of my shop page on Woocommerce. I’ve edited the archive-product.php file to include the field name, but it won’t display. If I replace the code with “test text” this does display. Any ideas?

    <div class="after-shop-text">
    <?php the_field('after-shop-text'); ?>

    That doesn’t show, but:

    <div class="after-shop-text">
    test text

    Does show.


  • Hi @winkweb

    Could you please make sure that you added the code inside The Loop? The issue you have mostly occurred because you were trying to execute the the_field() function outside of The Loop. To fix it, you need to pass the post/page ID as the second parameter to the get_field() function like this:

    get_field(‘custom_field_name’, 99)

    Where “99” is the post/page ID where the custom field is assigned. This page should give you more idea about it:

    I hope this helps 🙂

  • Thanks James,

    Yes I suspect it may be outside of the loop then. I’ll try what you’ve mentioned. Thanks!!!

  • Perfect, thanks James. I placed the following code within the end of the loop and it has shown the field

    $value = get_field( "after-shop-text", 8 );
    echo $value;

    Many thanks!!!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘ACF + Woocommerce Value Not Displaying’ is closed to new replies.