• Resolved alortiz3

    (@alortiz3)


    alortiz3

    Hello,

    I’ve been trying to add an ACF field to my invoices and for unknown reasons I can not get it to work. I’ve tried using the following code without much success. The ACF field meta is customer_no. I’ve used USER_customer_no and _customer_no and still getting a blank display. Any assistance will be appreciated.

    /* Add Account Number to Invoice */
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_customer_no', 10, 2 );
    function wpo_wcpdf_customer_no ($template_type, $order) {
        if ($template_type == 'invoice') {
            ?>
            <tr class="customer-no">
                <th>Account No: </th>
                <td><?php echo $order->get_meta('customer_no'); ?></td>
            </tr>
            <?php
        }
    }
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @alortiz3,

    Could you show us a screenshot of this custom field from the ACF settings? For that you could use a free service like imgbb.com.

    Looking at this thread regarding ACF, it sounds to me like you should be using the_field(), like this:

    
    the_field( 'customer_no', $order->get_id() )
    

    Instead of using $order->get_meta()

    ACF documentation — the_field()

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    Thank you for your prompt response. Tried with the suggested code, got the same result.
    Attached is the screenshot that you requested. https://ibb.co/yYXKrKr

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @alortiz3,

    Could you share a screenshot of the field & its value from the Edit-Order screen? Like this:
    custom-Field-ACF

    From the settings, is the field Active?

    You also mentioned that “the result is the same”, but what is the result? Is the “Account No:” text visible? Completely blank? Error message?

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    Here are the screenshots. One shows the field and the value, the other shows the result in the Invoice. https://ibb.co/7X16csT
    https://ibb.co/PMQ4qv8

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @alortiz3,

    For me, this works both with the original $order->get_meta('meta_key_here') & the other function I sent to you, which leads me to believe that the field is empty in the order.

    I expected your screenshot of the Custom Field from the Edit-Order page to look like mine, but it’s quite different – so I’m wondering if you’re on the correct screen.

    If you install the WC Store Toolkit plugin, you’ll be able to see all the meta-data in your order under Order Post Meta, like so (_juju):

    Screenshot-2022-03-31-14-48-56
    Screenshot-2022-03-31-14-49-34

    This will help us confirm whether or not the ‘customer_no’ field is present (& populated) in the order.

    • This reply was modified 2 years, 8 months ago by Darren Peyou.
    • This reply was modified 2 years, 8 months ago by Darren Peyou. Reason: additional sentence at end
    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    I just tried a newer order to see if there are any differences. As you can see on the attached screen the Account Number is present, but it does not show in the invoice. We do not include the account number in the order details which why you don’t see it in the edit orders screen. The account number is part of the user’s profile. https://ibb.co/JyTjpFL

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    The field does not show up in the Order Post Meta area. Any other suggestions?

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @alortiz3,

    I’m afraid that means the field isn’t present in the order. Since we are dealing with the ACF plugin, from the settings, could you show us a screenshot of the Location block of this field? It should be right under the items in the 1st screenshot you shared.

    ACFLocation

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    Here’s the screenshot that you requested: https://ibb.co/Qkq37CQ

    Thanks!

    Plugin Contributor Ewout

    (@pomegranate)

    $order->get_meta() is for pulling order meta, but it looks like your ACF field is for User meta. More information about displaying user meta is in our documentation here: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-user-data/

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    This has been solved using the suggested code. Thank you very much!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘ACF Custom Fields’ is closed to new replies.