vincmeister
vincmeister

Reputation: 191

Show Custom Field On Woocommerce View Order Page

I want to show Air Waybill on customer 'view order' page of woocommerce I create a custome field named AWB , value xxx

How to show them on the view order page of woocommece Thank you

Upvotes: 2

Views: 11782

Answers (2)

Maha Dev
Maha Dev

Reputation: 3965

Overriding order-details.php is bad practice, because when you update the woocommerce version, it resets everything you made changes in woocommerce core files. Better option is to use themes functions.php to show custom field in view orders page like this :

function action_woocommerce_order_details_after_customer_details($order) {

   echo get_post_meta( $order->id, 'awb', true );
}

add_action('woocommerce_order_details_after_customer_details', 'action_woocommerce_order_details_after_customer_details', 10, 1);

Upvotes: 9

nishant
nishant

Reputation: 489

You can override templates->order->order-detals.php to edit view order page. just print_r($item_meta); below the $item_meta->display(); and you will get get an array including your custom field value on view order page. Now fetch your custom field data from the array.

Or Use this query below $item_meta->display();

$pid=$item_meta->meta['_product_id'][0];
$custom_val=$wpdb->get_var("select meta_value from wp_postmeta where post_id = {$pid} AND meta_key='AWB'"); echo "Air Waybill: ".$custom_val;

Note: AWB =custom field name

Upvotes: 1

Related Questions