Display custom checkout field value in Woocommerce admin order edit pages

丶灬走出姿态 提交于 2019-12-07 23:14:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/49946189/display-custom-checkout-field-value-in-woocommerce-admin-order-edit-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!