Home › Forums › Front-end Issues › Having trouble adding a custom field to a Woocommerce product page › Reply To: Having trouble adding a custom field to a Woocommerce product page
Ok, in way of an update, I’ve done a bit more investigation and discovered the following. Using <?php echo get_field('custom_bg', $product->ID); ?>
correctly displays the image from the custom field – YAY!
However, this only works on certain products! Right now, during testing, I only have two active Woocommerce products, with IDs 98 and 106. I’ve added some debug code to the page so I know what the current page ID is at any time. When I visit product 106, the debug code correctly shows 106, and the custom_bg field is displayed. And when I visit product 98 I see 98 in the debug code but no custom_bg field displays. What’s most perplexing is when I visit my Woocommerce Shop page, the debug code shows 98.
Is this expected behaviour? Is the ID clash what’s stopping the custom_bg field from displaying?
I’m going to add another product to see if it displays there…
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.