so I have some Advanced Custom Fields on my product page. They are displayed in the shop loop, like so:

add_action('woocommerce_after_shop_loop_item_title', 'tagline', 5);
function tagline() {
    global $product;
    $product_id = $product->get_id();
    if (isset(get_fields()['product_tagline'])) {
        $tagline = get_fields()['product_tagline'];

        echo '<p class="tagline">' . $tagline . '</p>';

I'm also using ACF to select products in a post, so if we mention products in a blog post, I can select them to display as a sidebar. I'm struggling with getting the $tagline from my product fields to use in my sidebar.

I've tried $tagline = get_fields()['product_tagline']; but the result is null. Any idea of where I'm going wrong?

  • 1
    You have to pass the product ID as the first parameter to "get_fields()" function, because the default value for this parameter is the current global post ID which is the single post being displayed not the product.
    – Aboelabbas
    Aug 29 at 15:56
  • Yes, that worked! And it makes sense, thank you!
    – sackadelic
    Aug 29 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.