If you want to display the product description on the PDF invoice or packing slip, you can in two ways: by adding some code (an action) to your themes functions.php, or in a custom template (for full control over the exact position).
With a template action hook #
This is the most update proof option, because you don’t have to create a separate custom template. You can either print this before or after the item meta, for more information, check out the list of PDF template action hooks.
Add this to your themes functions.php
:
Short description #
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_description', 10, 3 ); function wpo_wcpdf_show_product_description ( $template_type, $item, $order ) { if (empty($item['product'])) return; $_product = $item['product']->is_type( 'variation' ) ? wc_get_product( $item['product']->get_parent_id() ) : $item['product']; if ( method_exists( $_product, 'get_short_description' ) ) { $description = $_product->get_short_description(); printf('<div class="product-description">%s</div>', $description ); } }
Full description #
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_full_description', 10, 3 ); function wpo_wcpdf_show_product_full_description ( $template_type, $item, $order ) { if (empty($item['product'])) return; $_product = $item['product']->is_type( 'variation' ) ? wc_get_product( $item['product']->get_parent_id() ) : $item['product']; if ( method_exists( $_product, 'get_description' ) ) { $description = $_product->get_description(); printf('<div class="product-description">%s</div>', $description ); } }
Variation description #
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_variation_description', 10, 3 ); function wpo_wcpdf_show_product_variation_description ( $template_type, $item, $order ) { if (empty($item['product'])) return; if (!empty( $item['variation_id'] )) { printf('<div class="product-description">%s</div>', $item['product']->get_description() ); } }
If you want to limit this to the packing slip (short description):
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_description', 10, 3 ); function wpo_wcpdf_show_product_description ( $template_type, $item, $order ) { if (empty($item['product'])) return; if ( $template_type == 'packing_slip') { $_product = $item['product']->is_type( 'variation' ) ? wc_get_product( $item['product']->get_parent_id() ) : $item['product']; if ( method_exists( $_product, 'get_short_description' ) ) { $description = $_product->get_short_description(); printf('<div class="product-description">%s</div>', $description ); } } }
Similarly, you can limit this to the invoice by replacing packing-slip
with invoice
.
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 product description to appear. Note that this has to be in the order items table!
Short description #
<?php if ( !empty($item['product']) ) { $_product = $item['product']->is_type( 'variation' ) ? wc_get_product( $item['product']->get_parent_id() ) : $item['product']; if ( method_exists( $_product, 'get_short_description' ) ) { echo $_product->get_short_description(); } } ?>
Full description #
<?php if (!empty($item['product'])) { $_product = $item['product']->is_type( 'variation' ) ? wc_get_product( $item['product']->get_parent_id() ) : $item['product']; if ( method_exists( $_product, 'get_description' ) ) { echo $_product->get_description(); } } ?>
Variation description #
<?php if ( !empty( $item['variation_id'] ) ) { if ( !empty($item['product']) ) { echo $item['product']->get_description(); } } ?>