• Hi,

    I want to add a custom field that I’ve created with a third party plugin, and the Key_meta_data is billing_wooccm12, it’s an ID. I followed your instructions but nothing is shown in the invoice, not even the label. I added this code at the end of the theme functions.php file. I’m using Astra theme, and the plugin I used to create the custom field is “WooCommerce Checkout Manager”. What am I doing wrong?

    Also I have to mention that this field is only shown if a previous question is answered Yes. But in this case the order that I used to do my test the answer was yes and the field was fulfilled, but no data was shown in the invoice.

    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    
        if( get_post_meta( $order->id, 'billing_wooccm12', true ) ) {
            $new_fields['billing_wooccm12'] = array(
                'label' => 'ID:',
                'value' => get_post_meta( $order->id, 'billing_wooccm12', true )
            );
        }
    
    
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • moksha shah

    (@mokshasharmila13)

    Hi @bluelee22

    Maybe it’s not fetching from WooCommerce, but your code is perfect. We are sharing you one more solution, try that code and let us know if it’s working or will try some other solution.

    function example_custom_order_fields( $fields, $order ) {
        $new_fields = array();
    
        if( get_post_meta( $order->id, '_billing_wooccm12', true ) ) {
            $new_fields['_billing_wooccm12'] = array(
                'label' => 'ID:',
                'value' => get_post_meta( $order->id, '_billing_wooccm12', true )
            );
        }
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    Please let us know if you need any help ??.

    Regards, Moksha.

    Thread Starter bluelee22

    (@bluelee22)

    Thanks for the quick answer Mokhsa, it’s now working, but as these fields are not required is there a way to hide label & value when the fields are empty?

    moksha shah

    (@mokshasharmila13)

    Hi @bluelee22

    Good to know that your first problem is solved but for hiding the label and value, we need to test that with multiple code in your site.

    Regards, Moksha

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add custom field to invoice’ is closed to new replies.