Displaying product attributes

If you have set up attributes for your products, there’s 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

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 attributes to appear. Note that this has to be in the order items table!

<?php if(!empty($item['product'])) $wpo_wcpdf->product_attribute('Attribute name', $item['product']); ?>

Replace ‘Attribute name’ with the name of your product attribute.

It is also possible to display product attributes 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_product_attributes', 10, 3 );
function wpo_wcpdf_show_product_attributes ( $template_type, $item, $order ) {
	global $wpo_wcpdf;
	if(empty($item['product'])) return;
	printf('<div class="product-attribute">Attribute name: %s</div>', $wpo_wcpdf->get_product_attribute('Attribute name', $item['product']));
}

or limited to the packing slip:

add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_attributes', 10, 3 );
function wpo_wcpdf_show_product_attributes ( $template_type, $item, $order ) {
	global $wpo_wcpdf;
	if(empty($item['product'])) return;
	if ($template_type == 'packing-slip') {
		printf('<div class="product-attribute">Attribute name: %s</div>', $wpo_wcpdf->get_product_attribute('Attribute name', $item['product']));
	}
}