• Resolved Anonymous User 13411357

    (@anonymized-13411357)


    Hey,

    Following various guidelines I’ve tried to implement an ACF custom field (which is entered on product level by the admin) on the invoice between the product name and the meta data for the variable.

    I’ve used this line of code in the functions.php. It’s showing the title “Pattern color:” but not showing the value. Could you please guide me in fixing this?

    
    add_action( 'wpo_wcpdf_before_item_meta', 'sss_invoice_pattern_color', 10, 2 );
    function sss_invoice_pattern_color ($template_type, $order) {
        $document = wcpdf_get_document( $template_type, $order );
        if ($template_type == 'invoice') {
            ?>
            <div class="pattern-color-invoice">
                <strong>Pattern color:</strong>
    			<?php the_field( 'pattern_color' ); ?></div>
            <?php
        }
    }

    Many thanks,
    Reijer

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @house-of-sovereignty,

    In the following guide you can find an example of adding a product custom field to your document with a code snippet: Displaying product custom fields

    Plugin Contributor Ewout

    (@pomegranate)

    Also note that your function parameters are incorrect for the wpo_wcpdf_after_item_meta action hook you used (which has 3 instead of 2). You can use the ACF the_field() function too, but since this is not ran in the actual product page, you will need to pass the product ID as well (documentation here):

    
    add_action( 'wpo_wcpdf_after_item_meta', 'sss_invoice_pattern_color ', 10, 3 );
    function sss_invoice_pattern_color ( $template_type, $item, $order ) {
        if ( $template_type == 'invoice' ) {
            ?>
            <div class="pattern-color-invoice">
                <strong>Pattern color:</strong>
                <?php the_field( 'pattern_color', $item['product_id'] ); ?>
            </div>
            <?php
        }
    }
    
    Thread Starter Anonymous User 13411357

    (@anonymized-13411357)

    Great guys!

    Sorry for the late reply, but this was a great help!

    All the best,
    Reijer

    Plugin Contributor Ewout

    (@pomegranate)

    No problem, glad to hear it helped!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display ACF field on invoice’ is closed to new replies.