Home › Forums › Front-end Issues › acf inside functions.php › Reply To: acf inside functions.php
Hi @pansotdev
There are some syntax issues in your code.
First, you can’t use “#” for the comment. Kindly use “//” instead.
Second, echo is used only to print text, not the code like in your example.
Third, it’s possible that the function is executed outside of WordPress loop. In this case, you need to pass the product ID to the second get_field() parameter. So your code should be like this:
function woocommerce_product_expire() {
// get the current post in the loop
global $post;
//Call the post expirator acf field
?>
<p>
<?php if( get_field('expires', $post->ID) ): ?>
<p>expires: </p>
<?php the_field('expires', $post->ID); ?>
<?php endif; ?>
</p>
<?php
}
I hope this makes sense 🙂
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.