1
votes

I am using "Show hide custom WooCommerce checkout field based on selected payment method" answer to one of my questions, to show / hide a custom checkout billing field, and it works fine.

Question: Is it possible to show my Custom field in WooCommerce orders in the admin panel?

2

2 Answers

2
votes

To display "billing_options" custom checkout billing field value in admin order pages on the billing information column, use the following:

add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_billing_options_value_in_admin_order', 10, 1 );
function display_billing_options_value_in_admin_order($order){
    if( $value = get_post_meta( $order->get_id(), '_billing_options', true ) )
        echo '<p><strong>'.__('Invoice Number', 'woocommerce').':</strong> ' . $value . '</p>';
}

enter image description here

To make this custom checkout billing field appear as editable in backend use the following:

add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
function custom_admin_billing_fields( $fields ) {
    $fields['options'] = array(
        'label' => __('Invoice Number', 'woocommerce'),
        'show'  => true,
    );
    return $fields;
}

enter image description here

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

0
votes
add_action( 'woocommerce_admin_order_data_after_order_details', 'mycustom_order_meta_general' );

function mycustom_order_meta_general( $order ){  ?>

        <br class="clear" />
        <h4>Gift Order <a href="#" class="edit_address">Edit</a></h4>
        <?php 
            /*
             * get all the meta data values we need
             */ 
            $_mycustomfield = get_post_meta( $order->get_id(), '_mycustomfield', true );

        ?>
        <div class="address">
            <p><strong>My Custom Field</strong></p>
            <?php

                if( $_mycustomfield ) : 
                ?>
                    <p><strong>MY custom:</strong> <?php echo $_mycustomfield ?></p>

                <?php
                endif;
            ?>
        </div>
<?php } ?>