Showing custom fields on Order Page in Woocommerce

I used a function to add a custom field to order meta with the action woocommerce_checkout_update_order_meta. I can see the custom fields on the admin page, but I cannot make those custom fields appeared in the order page of the website.

Here is the code:

Read More
add_action( 'woocommerce_checkout_update_order_meta', 'time_field_update_order_meta' );

function time_field_update_order_meta( $order_id ) {
    if ( $_POST['time_1'] ) {
        update_post_meta( $order_id, 'Time 1', sanitize_text_field( $_POST['time_1'] ) );
    }
    if ( $_POST['time_2'] ) {
        update_post_meta( $order_id, 'Time 2', sanitize_text_field( $_POST['time_2'] ) );
    }
}

Is there another action or filter that I can add on my functions.php to display those custom fields too?

Related posts

1 comment

  1. You could try using a similar function like the one shown here on github: https://gist.github.com/woogist/6267983

    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 get_post_meta( $order->id, 'Time 1', true );
        echo get_post_meta( $order->id, 'Time 2', true );
    }
    

Comments are closed.