• minamt

    (@minamt)


    Recently, I’ve customized the PDF invoice generated by the plugin by adding custom fields to it. These custom fields are crucial for providing additional information to our customers. However, while the custom fields display correctly on the PDF invoice itself when viewed through the document, their value appear blank when the invoice is sent as an attachment in customer emails.
    Any assistance or insight you can provide would be greatly appreciated. Thank you for your attention to this matter.

    • This topic was modified 7 months ago by minamt.
    • This topic was modified 7 months ago by minamt.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hello @minamt,

    > when viewed through the document
    What do you mean? The PDF Preview?

    Do they only appear in the PDF Preview or do they also appear when generated manually?

    create-pdf-proforma-invoice-button-order-details-screen.png
    (Disregard the arrow)

    bulk-actions-pdf-proforma-invoice.png
    (WooCommerce Bulk actions at WooCommerce > Orders)

    proforma-Invoice-button.png
    (Manual PDF Creation: Action Buttons for PDF Creation)


    Do you have any relevant errors?

    Thread Starter minamt

    (@minamt)

    Hi Darren,
    The value of the custom fields appear blank only when sent as an attachment in email, otherwise in preview, generated manually or using the download or link shortcode it’s appearing fine

    Plugin Contributor dwpriv

    (@dwpriv)

    @minamt could you share the code snippet that you’re using to add these fields, please?

    Thread Starter minamt

    (@minamt)

    @dwpriv,
    Sure here’s the code I added to the custom invoice template

    <?php 
    $approval_code = $order_key->get_meta('approval_code');
    $transaction_id = $order_key->get_meta('transaction_id');
    $transaction_time = $order_key->get_meta('transaction_time');
    $orderNumber = $order_key->get_meta('orderNumber');
    ?>
    
    <table class="cib-data">
    	<tr>
    		<td class = "order-data">
                Transaction ID: <?php echo $transaction_id; ?>
    		</td>
    	</tr>
        <tr>
    		<td class = "order-data">
                Order number: <?php echo $orderNumber; ?>
    		</td>
    	</tr>
        <tr>
    		<td class = "order-data">
                Approval code: <?php echo $approval_code; ?>
    		</td>
    	</tr>
        <tr>
    		<td class = "order-data">
                Transaction time: <?php echo $transaction_time; ?>
    		</td>
    	</tr>
    </table>
    <?php do_action( 'wpo_wcpdf_before_order_details', $this->get_type(), $this->order ); ?>

    Is it the way the action is added?

    Plugin Contributor dwpriv

    (@dwpriv)

    The issue may be with your custom template. You can try the below edit to your snippet that you can add to the template-functions.php file in your custom template folder. You can then remove the prior code above. You can alternative paste it in a plugin like Code Snippets

    add_action( 'wpo_wcpdf_before_order_details', function( $document_type, $order ) {
    	if ( !empty ( $order ) ) {
    		$approval_code = $order->get_meta('approval_code');
    		$transaction_id = $order->get_meta('transaction_id');
    		$transaction_time = $order->get_meta('transaction_time');
    		$orderNumber = $order->get_meta('orderNumber');
    		?>
    			<table class="cib-data">
    				<tr>
    					<td class = "order-data">
    						Transaction ID: <?php echo $transaction_id; ?>
    					</td>
    				</tr>
    				<tr>
    					<td class = "order-data">
    						Order number: <?php echo $orderNumber; ?>
    					</td>
    				</tr>
    				<tr>
    					<td class = "order-data">
    						Approval code: <?php echo $approval_code; ?>
    					</td>
    				</tr>
    				<tr>
    					<td class = "order-data">
    						Transaction time: <?php echo $transaction_time; ?>
    					</td>
    				</tr>
    			</table>
    		<?php
    	}
    }, 10, 2 );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Fields Not Appearing in Email Attachments’ is closed to new replies.