• Resolved page52

    (@page52)


    Hello, is it possible to add custom checkout fields created with a third party plugin to the invoices and delivery notes?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Upendra Kapse

    (@wpupen)

    Hello,

    Yes, we do have a filter using which you can add the custom fields created with a third-party plugin by using the meta keys for those fields.

    You can refer to this example function that adds the VAT field, you can modify this function based on the field title and the field meta key that you want to fetch, you can add this function in either the functions.php file of your child theme or add it as a snippet using the Code Snippets plugin.

    /**
     * An example that adds a 'VAT' field to the end of the list. 
     */
    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
            
        if( get_post_meta( $order->id, 'your_meta_field_name', true ) ) {
            $new_fields['your_meta_field_name'] = array( 
                'label' => 'VAT',
                'value' => get_post_meta( $order->id, 'your_meta_field_name', true )
            );
        }
        
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    Kind Regards,
    Upendra.

    Thread Starter page52

    (@page52)

    Thank you so much Upendra; this worked for me for a custom field introduced by a different plugin but not this one. Could you show me what the code would look like if there were TWO custom fields to add?

    Plugin Support Upendra Kapse

    (@wpupen)

    Hello,

    The example code to add two custom fields to the Invoice will look like this:

    /**
     * Add this code snippet in functions.php file of your currently active theme.
     * An example that adds a 'VAT' and 'Customer Number' field to the end of the list. 
     */
    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
            
        if( get_post_meta( $order->id, 'your_meta_field_name', true ) ) {
            $new_fields['your_meta_field_name'] = array( 
                'label' => 'VAT',
                'value' => get_post_meta( $order->id, 'your_meta_field_name', true )
            );
        }
        
        if( get_post_meta( $order->id, 'your_meta_field_name', true ) ) {
            $new_fields['your_meta_field_name'] = array( 
                'label' => 'Customer Number',
                'value' => get_post_meta( $order->id, 'your_meta_field_name', true )
            );
        }
        
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    I hope this helps.

    Kind Regards,
    Upendra.

    Thread Starter page52

    (@page52)

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Custom Fields from 3rd Party Plugin to Invoice/delivery note’ is closed to new replies.