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
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