Hello @petfresh
Is not very easy to achieve that, because it’s difficult to know the items height effectively. Nevertheless, please add the code snippet below to your functions.php file:
add_filter( 'wpo_wcpdf_paper_format', 'wcpdf_dynamic_page_size', 10, 3 );
function wcpdf_dynamic_page_size( $paper_format, $document_type, $document ) {
// set width & height in mm
$width = 80;
$min_height = 150;
$base_height = 140;
$height = $base_height;
if ( !empty($order = $document->order )) {
foreach( $order->get_items() as $item ) {
$product = $item->get_product();
if( $product->get_type() == 'simple' ) {
$height += 12; // adjust for simple products
} else {
$height += 50; // adjust for variable products ( includes meta )
}
}
$height = max($min_height, $height);
} else {
$height = $min_height;
}
//convert mm to points
$paper_format = array( 0, 0, ($width/25.4) * 72, ($height/25.4) * 72 );
return $paper_format;
}
If you never worked with actions/filters, please read this documentation page: How to use filters
Hi,
Wanting to make it so that for an item without any meta printed, it should only give an extra 15 of space, and if it does have meta, it should provide 30 of space.
I changed part of the snippet to this, but I am having trouble detecting if an item has meta. Could you help?
if ( !empty($order = $document->order )) {
foreach( $order->get_items() as $item ) {
$product = $item->get_product();
if (isset ($item['meta'])) {
$height += 30; // adjust for simple products
} else {
$height += 15; // adjust for simple products
}
$height = max($min_height, $height);
} else {
$height = $min_height;
}