• Resolved flostone

    (@flostone)


    Hi
    I want to add notes to an order that are displayed/printed on the packing slip PDF. Is that possible?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    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 filters

    In 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 );
    Thread Starter flostone

    (@flostone)

    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?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Yes, this can be also possible! You have two options to do this:

    1. By adding a custom block to the packing slip with the customizer, included in Premium Templates, using the {{invoice_notes}} placeholder, like this:

      A screenshot that display the invoice notes placeholder

    2. 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 );
    Thread Starter flostone

    (@flostone)

    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
    Florian

    Plugin Contributor Yordan Soares

    (@yordansoares)

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    In brief, if you have a child theme, you can add code snippets in its functions.php file: don’t add code snippets to the functions.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 😉

    Thread Starter flostone

    (@flostone)

    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.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that, @flostone!

    Let us know if you need anything else 🙂

    Thread Starter flostone

    (@flostone)

    Hi @yordansoares

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add notes to packing slip’ is closed to new replies.