• Resolved mariosmode

    (@mariosmode)


    Hi, I’m using your plugin alongside Woocommerce Admin Custom Order Fields plugin which I used to add a custom field to the order screen.

    According to the Woocommerce Admin Custom Order Fields documentation, The meta keys for each admin custom order field are in the format of _wc_acof_{id} where {id} is replaced by the integer id of the field.

    Once you know the id, you can use get_post_meta( $order_id, '_wc_acof_{id}', true ) to get the value of that custom field for a particular order.

    So I opened invoice.php from your plugin and tried to add that piece of code to the table with class order-data-addresses.

    But for some reason, nothing is being echoed.

    What would be the way for adding a custom field to the pdf?

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

    (@pomegranate)

    Hi!
    The get_post_meta function is actually deprecated for use on order meta since WooCommerce 3.0, with the introduction of CRUD and the move to custom tables in future releases.
    Instead of using:

    
    get_post_meta( $order_id, $meta_key, true );
    

    You should therefor use:

    
    $order = wc_get_order( $order_id ); // omit this if you have the order object already
    $meta_value = $order->get_meta( $meta_key );
    

    That said, you can still use get_post_meta, I just wouldn’t recommend it if you want to be compatible with future releases of WC 🙂
    The reason your code doesn’t work is because $order_id is not set within invoice.php. It’s stored in $this->order_id and the order object is stored in $this->order.

    This should work for you:

    
    echo $order->get_meta( '_wc_acof_{id}' );
    

    Alternatively we have some shorthand functions available too, but if you are a coder you may find the above more useful.

    Hope that helps!
    Ewout

    Thread Starter mariosmode

    (@mariosmode)

    Hello, thank you for your help. I actually got what I needed with $this->custom_field('_wc_acof_2_formatted');

    Additionally, I would like to hide invoice date on the PDF if the payment was made with BACS. Because I need to have an exact date of when the payment was received for my accounting. If the payment was made yesterday, and order is completed today, the date won’t be correct on the invoice.

    Any help with that would be appreciated.

    Plugin Contributor kluver

    (@kluver)

    Hi @mariosmode,

    The easiest solution might be to add the payment date to your invoice instead of hiding the invoice date. With our Premium Templates extension it is super easy to add order data like this with the customizer. Just add a custom block. Here you can read how: Using custom blocks

    With kinds regards,

    Michael

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Echoing Order custom field in PDF’ is closed to new replies.