Add notes to packing slip
-
Hi
I want to add notes to an order that are displayed/printed on the packing slip PDF. Is that possible?Thanks
-
Hi @flostone,
Do you want to display the same note in all your packing slips, or do you want to add different notes in each order?
If the first, you can achieve it with this code snippet:
/** * WooCommerce PDF Invoices & Packing Slips: * Displays a custom note in all the PDF packing slips */ add_action( 'wpo_wcpdf_after_customer_notes', function( $document_type, $order ){ if ( $document_type == 'packing-slip' ) { echo '<h3>Important:</h3>'; echo 'Your custom notes goes here!'; } }, 10, 2 );
If you haven’t worked with code snippets (actions/filters) or
functions.php
before, read this guide: How to use filtersIn the case that you want to add a different note for each order, first you’ll need to add an order custom field (Advanced Custom Fields is the best plugin I know to do this), and then you can display your custom notes for each order with this code snippet:
/** * WooCommerce PDF Invoices & Packing Slips: * Displays a custom note in the PDF packing slips */ add_action( 'wpo_wcpdf_after_customer_notes', function( $document_type, $order ){ if ( $document_type == 'packing-slip' && ( $custom_note = $order->get_meta( 'custom_note' ) ) ) { echo '<h3>Important:</h3>'; echo $custom_note; } }, 10, 2 );
Thank you so much @yordansoares
I want to add individual notes to each order (if needed), so the second solution would fit.
Because the PDF-plugin already has this feature with “PDF document data / notes” implemented for invoices out of the box, I thought that there might be a simple way to add this for packing-slips to? Optimally without the need to add additional plugins and dependencies.
Maybe you have an idea?
Yes, this can be also possible! You have two options to do this:
- By adding a custom block to the packing slip with the customizer, included in Premium Templates, using the
{{invoice_notes}}
placeholder, like this: - Or with some PHP code through a code snippet like this:
/** * WooCommerce PDF Invoices & Packing Slips: * Show the invoice notes on packing slips too */ add_action( 'wpo_wcpdf_before_customer_notes', function( $document_type, $order ) { if ( $document_type == 'packing-slip' ) { $document = wcpdf_get_document( 'invoice', $order ); if ( $document && $document->exists() ) { ?> <div class="notes"> <h3>Notes:</h3> <?php echo $document->document_notes(); ?> </div> <?php } } }, 10, 2 );
Great, thank you @yordansoares .
One more question regarding the the 2. option (adding code-snippet). In what file at what position to place the snippet?Thank you
FlorianIf you haven’t worked with code snippets (actions/filters) or
functions.php
before, read this guide: How to use filtersIn brief, if you have a child theme, you can add code snippets in its
functions.php
file: don’t add code snippets to thefunctions.php
file from your parent theme, because you may lose your customizations after updating your parent theme! The another way to add code snippets, that is safer in my humble opinion, is to use the Code Snippets plugin: This plugin stores the code snippets in your database, so you don’t have to worry about losing your customizations after updating your plugins or theme 😉Thank you @yordansoares
Your magic snippet works perfectly in my child-themes functions.php and does exactly what I was looking for (request solved) 😉
Thank you so much for your help!
Best wishes from Switzerland,
Florian- This reply was modified 2 years, 4 months ago by flostone.
I’m glad to hear that, @flostone!
Let us know if you need anything else 🙂
Your code-snippet works fine, but I have one detail that can be optimized:
Do you have an easy solution to hide the title “notes” when there are no notes? At the moment the title shows on every packing-slip, even if there are no notes.
Thank you & best regards.
Florian
- By adding a custom block to the packing slip with the customizer, included in Premium Templates, using the
- The topic ‘Add notes to packing slip’ is closed to new replies.