• Resolved tooeleshootingsupply

    (@tooeleshootingsupply)


    Hello,

    I have followed all the examples in your other support threads, and am still coming up blank. I’m trying to incorporate custom fields into my Invoices from Checkout Field Manager for WC (not to be confused with Woocommerce Checkout Manager, different plugin). They’ve assured me that their custom fields are titled exactly what I dictate the name is on their backend, for example ‘this_field’.

    So far I’ve done the following:
    – Created custom template
    – Added native WooCommerce fields to the template (e-mail and phone #)

    and for the custom fields, I have the following code added below the Payment Method code in the invoice template (including the payment method lines below for clarification on location):

    <span class="order-payment-label"><?php _e( 'Payment Method:', 'wpo_wcpdf' ); ?></span>
    <span class="order-payment"><?php $wpo_wcpdf->payment_method(); ?></span><br />
    <?php
    $ffl_dealer = get_post_meta($wpo_wcpdf->export->order->id,'FFL Dealer',true);
    		if (isset($ffl_dealer)) {
    		echo $ffl_dealer;
    }
    ?>
    <?php
    $order_notes = get_post_meta($wpo_wcpdf->export->order->id,'Order Notes',true);
    		if (isset($order_notes)) {
    		echo $order_notes;
    }
    ?>
    <?php $wpo_wcpdf->custom_field('FFL Dealer', 'FFL Dealer:',  true); ?>

    The last line I added to see what it did, and all it makes is an empty field show up on my invoices that says “FFL Dealer:”. Other than that, no change is made at all to the invoice.

    As you can see I’m just trying to pull two custom fields, one called ffl_dealer and the other called order_notes. I feel like this is an extremely easy fix and I’m just doing something stupid. Can you please point me in the right direction?

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

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

    (@pomegranate)

    Hi There,
    You’re almost there! You are fetching custom fields “FFL Dealer” and “Order Notes”, but as you already indicated you need “ffl_dealer” and “order_notes”. The first argument of the custom_field function is the field name, the second is the label. (and for the get_post_meta, it’s also the field name that needs to be passed)

    The folllowing should do the trick, note that you passed “true” so it will indeed show the label if the field is empty too (see FAQ).

    <?php $wpo_wcpdf->custom_field('ffl_dealer', 'FFL Dealer:',  true); ?>
    <?php $wpo_wcpdf->custom_field('order_notes', 'Order Notes:',  true); ?>

    The other code is not necessary with the new custom_field function (which is a lot cleaner).

    Let me know if that works for you!
    Ewout

    Thread Starter tooeleshootingsupply

    (@tooeleshootingsupply)

    Hey Ewout,

    That worked!! Thank you so much for the direction, I knew it had to be close.

    Hi! i had the same problem and i try your code and work almost perfect, now i get the value before the name of the field.

    value-name: Value
    22222222RDNI/CIF: 22222222R

    (<span class=”order-payment-label”><?php _e( ‘Payment Method:’, ‘wpo_wcpdf’ ); ?></span>
    <span class=”order-payment”><?php $wpo_wcpdf->payment_method(); ?></span>
    <?php
    $DNI_CIF = get_post_meta($wpo_wcpdf->export->order->id,’DNI_CIF’,true);
    if (isset($DNI_CIF)) {
    echo $DNI_CIF;
    }
    ?>
    <?php $wpo_wcpdf->custom_field(‘DNI_CIF’, ‘DNI/CIF:’, true); ?>)

    what i’m doing wrong?

    thank you!

    Plugin Contributor Ewout

    (@pomegranate)

    You have some double code there, both the old and the new way. You only need one :o)

    <span class="order-payment-label"><?php _e( 'Payment Method:', 'wpo_wcpdf' ); ?></span>
    <span class="order-payment"><?php $wpo_wcpdf->payment_method(); ?></span>
    <?php $wpo_wcpdf->custom_field('DNI_CIF', 'DNI/CIF:', true); ?>

    You might want to insert a newline (<br />) there.

    Good luck!
    Ewout

    Thread Starter tooeleshootingsupply

    (@tooeleshootingsupply)

    Hey antoniorme,

    I can’t be sure, but try deleting the entire following section from the code:

    <?php
    $DNI_CIF = get_post_meta($wpo_wcpdf->export->order->id,'DNI_CIF',true);
    if (isset($DNI_CIF)) {
    echo $DNI_CIF;
    }
    ?>

    Mine looks like this now, I removed the entire first section of my code:

    <span class="order-payment-label"><?php _e( 'Payment Method:', 'wpo_wcpdf' ); ?></span>
    <span class="order-payment"><?php $wpo_wcpdf->payment_method(); ?></span><br />
    <?php $wpo_wcpdf->custom_field('_ffl_dealer', 'FFL Dealer:',  true); ?><br />
    <?php $wpo_wcpdf->custom_field('_order_notes', 'Order Notes:',  true); ?>

    Basically the entire get_post_meta section isn’t necessary now.

    THANK YOU!!

    Yesterday we broke our head finding a solution.

    Thank you again.
    Antonio & Amanda

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Checkout Fields on Invoice’ is closed to new replies.