Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter danna556

    (@danna556)

    Please tell me, can i have support to this topic, if no i want to know to start searching another plugin ??

    Plugin Author ThemeHigh

    (@themehigh)

    While checking the Plugin ‘WooCommerce PDF Invoices’, we could see that it gives a hook to add custom fields to billing addresses area in the PDF invoice which is “wpi_after_formatted_billing_address”. So please try to add the below code in your child theme’s ‘functions.php’ file to showing custom fields to your invoice.

    add_action('wpi_after_formatted_billing_address','thwcfd_view_additional_fields');
    function thwcfd_view_additional_fields($invoice){
    	$invoice_data = array();
    	$order_data = array();
    	$order_id = '';
    
    	foreach ( $invoice->get_invoice_info() as $info_id => $info ) {
    		$invoice_data = $invoice->get_invoice_info();			
    	}
    
    	$order_data = $invoice_data['order_number'];
    	$order_id = $order_data['value'];
    
    	if(!empty($order_id)){
            // Custom fields and its label.
    		$fields = array(
    			'additional_d' => 'Label'
    		);
    
    		foreach ($fields as $key => $label) {
    			$value = get_post_meta( $order_id, $key, true );
    			if(!empty($value)){
    				$html .= '<p><strong>'. $label .':</strong><br/> '. $value .'</p>';
    			}
    		}
    
    		if($html){
    			echo $html;	
    		}
    	}
    }

    Note:: The above code is an example for adding the custom field ‘additional_d’ to PDF invoice. So you needs to add all your custom fields name and its labels in the below-mentioned array in the above code.

    $fields = array(
    	'additional_d' => 'Label'
    );

    Hope this help.

    Thank you!

    Thread Starter danna556

    (@danna556)

    Thank u very much.
    I add code, but for some reason only “Order notes are showed”
    https://prnt.sc/pa96l0 here can u see my code
    thats my custom field with labels https://prnt.sc/pa9715
    Thats additional field showed only https://prnt.sc/pa97ch
    And thats my invoice how look like https://prnt.sc/pa97y4
    I will be very thankful if u can help me

    Plugin Author ThemeHigh

    (@themehigh)

    We have verified the code and could see that it is working fine. Could you please raise a ticket through our website? We hope our technical team will be able to help you.

    Thank you!

    Thread Starter danna556

    (@danna556)

    Okay, thank u very much ??

    Plugin Author ThemeHigh

    (@themehigh)

    We hope your issue is resolved now. We are going to mark this thread as resolved.

    Thank you!

    Hi I’m having the same problem, I have used the code to hook onto wpi_after_formatted_billing_address but no even a single field is showing. What was the solution to this? Thanks!

    Plugin Author ThemeHigh

    (@themehigh)

    @houseofbats1 You need to use the method suggested by the invoice plugin developer inorder to display the custom metadata in the invoice.

    You can refer the below link for more details:

    https://bg.www.ads-software.com/plugins/woocommerce-pdf-invoices/#how%20to%20add%20custom%20fields%2Fmeta-data%20to%20the%20pdf%20invoice%20template%3F

    Hope this will help.

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Hello, showing custom fields to Invoice’ is closed to new replies.