Table of Contents
If you have set up purchase notes for your products, there are two ways of displaying them: in a custom template (for full control over the exact position), or by adding some code (an action) to your themes functions.php
In a custom template #
First, you need to create a custom template by following instructions here: Creating a custom PDF template.
Then place the following snippet where you would like the purchase notes to appear. Note that this has to be in the order items table!
<?php if (!empty($item['product'])) { $purchase_note = $item['product']->get_purchase_note(); if ( !empty( $purchase_note ) ) { echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); } } ?>
With a template action hook #
It is also possible to display purchase notes without creating a custom template, by using one the template action hooks (before or after the item meta) and adding it to your themes functions.php
:
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_purchase_notes', 10, 3 ); function wpo_wcpdf_show_purchase_notes ( $template_type, $item, $order ) { if (!empty($item['product'])) { $purchase_note = $item['product']->get_purchase_note(); if ( !empty( $purchase_note ) ) { echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); } } }
or limited to the packing slip:
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_purchase_notes', 10, 3 ); function wpo_wcpdf_show_purchase_notes ( $template_type, $item, $order ) { if ( $template_type == 'packing-slip' && !empty($item['product']) ) { $purchase_note = $item['product']->get_purchase_note(); if ( !empty( $purchase_note ) ) { echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); } } }