4

I have the function in functions.php:

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['billing']['billing_infos'] = array(
        'type'      => 'textarea',
        'label'     => __('Podaj NIP', 'woocommerce'),
    'placeholder'   => _x('Tutaj możesz wpisać NIP', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     return $fields;
}   

This code is adding custom field to billing form. It's working fine because I see it when I make an order like normal user. The problem is with data from this field in admin panel. I can't see it. Any help on this please?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Daniel Kozina
  • 69
  • 2
  • 7

1 Answers1

3

This missing hooked function will display your custom fields in Order edit page, below Billing details:

add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_billing_infos_to_admin_order_meta', 20, 1 );
function display_billing_infos_to_admin_order_meta( $order ){
    echo '<p><strong>'.__('Podaj NIP').':</strong> ' . get_post_meta( $order->get_id(), '_billing_infos', true ) . '</p>';
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • How can one take this further by being able to edit the field value in the backend? In my case, customers sometime forget to add their Tax / VAT number and I have to manually add it for them. – Schalk Joubert Oct 08 '18 at 09:23
  • @user1664798, You should ask a new question related and notify me here. – LoicTheAztec Oct 08 '18 at 17:35
  • @LoicTheAztec , Thank you. here is the link to my question. Much appreciated! [link](https://stackoverflow.com/questions/52761161/editing-adding-woocommerce-custom-checkout-fields-on-order-admin-page) – Schalk Joubert Oct 11 '18 at 13:24