• Resolved 1cloudforall

    (@1cloudforall)


    Hi,

    We would like to make the height responsive because our paper roll is one large roll, is this possible?
    We tried editting the CSS but something is holding it back.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter 1cloudforall

    (@1cloudforall)

    Also, we are trying to get the order time shown on the PDF. But using Y/m/d \a\t g:i doesn’t seem to work. Is there another work around for this?

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! Since PDF is a static media size, you can’t really make it responsive, but you can probably get close with the filter that controls the media size, wpo_wcpdf_paper_format. This filter did not get any order information until now (9486819), so you will either need to download the latest version from github, or wait until the next release (early next week if everything goes to plan).

    With this updated version you can use this filter (tweaking the parameters for your setup) to change the height based on the number of items:

    
    add_filter( 'wpo_wcpdf_paper_format', 'wpo_wcpdf_paper_format_dynamic', 10, 3 );
    function wpo_wcpdf_paper_format_dynamic( $paper_format, $document_type, $document = null ) {
    	if (!empty($document) && !empty($document->order)) {
    		$order_items = $document->order->get_items();
    		$item_count = count($items);
    		// do your magic with the $item_count here, below example is all sizes in mm:
    		$width = 150;
    		$height = 150+40*$item_count;
    
    		//convert mm to points
    		$paper_format = array( 0, 0, ($width/25.4) * 72, ($height/25.4) * 72 );
    	}
    	return $paper_format;
    }
    

    What code are you currently using for the order time?

    Thread Starter 1cloudforall

    (@1cloudforall)

    Thank you, doesn’t work yet but I get the idea!

    For the order time i’m using:
    invoice.php:

    <tr class="order-date">
    					<th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->order_date("Y/m/d \a\t g:i"); ?></td>
    			
    				</tr>
    Plugin Contributor Ewout

    (@pomegranate)

    I see – the order date does not take any arguments so that’s why it doesn’t work ??
    You can however control the date format with a filter:

    
    add_filter( 'wpo_wcpdf_order_date', 'wpo_wcpdf_order_date_format', 10, 3 );
    function wpo_wcpdf_order_date_format( $order_date, $order_date_mysql, $document ) {
        return date_i18n( 'Y/m/d \a\t g:i', strtotime( $order_date_mysql ) );
    }
    

    Or if you prefer to do this directly in the template:

    
    <?php echo $this->order->get_date_created()->date_i18n("Y/m/d \a\t g:i"); ?>
    
    Thread Starter 1cloudforall

    (@1cloudforall)

    The date-filter is working perfectly!
    But the item_count is still giving some problems.

    I’ve added the filter to the functions like you said and also downloaded the newest version from GitHub. But it seems like the function does count the items to early which results in “0”.

    The filter I’ve added in functions:

    add_filter( 'wpo_wcpdf_paper_format', 'wpo_wcpdf_paper_format_dynamic', 10, 3 );
    function wpo_wcpdf_paper_format_dynamic( $paper_format, $document_type, $document = null ) {
    	if (!empty($document) && !empty($document->order)) {
    		$order_items = $document->order->get_items();
    		$item_count = count($items);
    		// do your magic with the $item_count here, below example is all sizes in mm:
    		$width = 102;
    		$height = 120 + 4 * $item_count;
    
    		//convert mm to points
    		$paper_format = array( 0, 0, ($width/25.4) * 72, ($height/25.4) * 72 );
    	}
    	return $paper_format;
    }
    

    Whenever I put the item_count manualy instead of the $item_count, it works how it should.
    $height = 120 + 4 * 11;

    Thanks in advanced!

    Plugin Contributor Ewout

    (@pomegranate)

    you’re correct, this was a typo:

    
    $item_count = count($items);
    

    should have been:

    
    $item_count = count($order_items );
    
    Thread Starter 1cloudforall

    (@1cloudforall)

    Thank you! Works perfect!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Responsive Height’ is closed to new replies.