Viewing 1 replies (of 1 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @ekinmedyanet,

    I see you’ve already managed to change the page size. To change the fundamental layout of the template you will need to create a custom template. Here you can change the structure of the header.

    When working with a thermal printer I’m assuming you’ll also need a dynamic page height. You could accomplish that with the following code snippet:

    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;
    }

    This will add extra millimeters to your page height based on the items in the order. This code snippet should be added to the functions.php of your child theme or via a plugin like Code Snippets. If you haven’t worked with code snippets or functions.php before please read this: How to use filters

    • This reply was modified 3 years, 11 months ago by kluver.
Viewing 1 replies (of 1 total)
  • The topic ‘Thermal printer template’ is closed to new replies.