In Woocommerce I am using a plugin called YITH WooCommerce PDF Invoice and Shipping List and I would like to add customer note to the PDF invoice.
I would like to add it after the first span line in the code below:
<span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>
<div class="notes">
<span><?php echo nl2br( $notes ); ?></span>
<?php do_action( 'yith_ywpi_after_document_notes', $document );?>
</div>
</div>
<?php
But i can't figure out how to get the customer note from $document
variable.
I have tried to use this answer thread: "Display Customer order comments (customer note) in Woocommerce" which looks pretty much like the same problem but still could'nt figure it out as $document->order->customer_message;
doesn't work.
Any help is appreciated.
Since Woocommerce 3 you can't access anymore properties From the WC_Order
object. You need to use the WC_Order
method [get_customer_note()
][1].
So from the $document
(YITH global object) you will use:
$document->order->get_customer_note();
To add customer notes to YITH invoice you can choose between 2 ways:
1) Using the available yith_ywpi_after_document_notes
action hook:
add_action( 'yith_ywpi_invoice_template_products_list', 'add_customer_notes_after_document_notes', 5 );
function add_customer_notes_after_document_notes( $document ) {
?><span><?php echo $document->order->get_customer_note(); ?></span><?php
}
Code goes in function.php file of your active child theme (or active theme). Untested (as I dont have the premium version of the plugin) but it should work normally (depending on the plugin settings).
2) Overriding templates (in your provided code):
<span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>
<div class="notes">
<span><?php echo nl2br( $notes ); ?></span>
<span><?php echo $document->order->get_customer_note(); ?></span>
<?php do_action( 'yith_ywpi_after_document_notes', $document );?>
</div>
</div>
<?php
It should work.
For the free plugin version
- There is no available hooks (like in the provided code)…
- The YITH PDF global object need to be called and it's not
$document
.
So you will be able to use the following code in templates/invoice/invoice-footer.php
template:
<?php global $ywpi_document; echo $ywpi_document->order->get_customer_note(); ?>