Support

Account

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 🙂