• Resolved oscarinside

    (@oscarinside)


    Hi, I’m trying to place a custom ACF field on the invoice but it doesn’t show it with the ACF code.

    I am using the following code:

    add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_custom_text', 10, 2 );
    function wpo_wcpdf_custom_text ($template_type, $order) {
        ?>
    	<br>
    	<h3> DETALES GENERALES </h3>
    	<br>
    	<p> <b>Hora de encuentro:</b> <?php the_field( 'duracion' ); ?> </p>
    	
    	<br>
    	<p>Gracias por reservar este tour con OV TRAVEL. ?Vivirás una excelente experiencia!</p>
    
        <?php
    }

    The result is this:
    https://cl.ly/63f9b2fe08f7

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    The function the_field() only works like that if you use it on a page where the post that this custom field is stored in is shown (like a product page). In other contexts (where multiple products/orders/posts etc can be visible) you need to pass the $post_id, see the documentation here: the_field()

    Assuming this is a custom field stored in the Order: you could add the order ID as the second parameter like so:

    
    the_field( 'duracion', $order->get_id() );
    

    If this is a custom field from the product, you will need to put it in a different hook (within the product table), like wpo_wcpdf_after_item_meta. More information here: Displaying product custom fields

    Thread Starter oscarinside

    (@oscarinside)

    Thank you. Now it works! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show ACF custom field’ is closed to new replies.