From this WooCommerce snippet found in Customizing checkout fields using actions and filters (where there is a little mistake), try the following:
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('My Field').':</strong><br>' . get_post_meta( $order->get_id(), 'billing_cif', true ) . '</p>';
}
You need to be sure that the correct meta_key
under wp_postmeta table is billing_cif
as it could be saved also like _billing_cif
instead.
Code goes in functions.php file of the active child theme (or active theme). It should works.
Or the same thing in a better way since WooCommerce 3:
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta( $order ){
$billing_cif = $order->get_meta('billing_cif'); // Get custom field value
if( ! empty( $billing_cif ) ) {
echo '<p><strong>'.__('CIF reference').':</strong><br>' . $billing_cif . '</p>';
}
}
Code goes in functions.php file of the active child theme (or active theme). It should works too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…