2014-09-03 90 views

回答

4

您可以使用下面的代碼:

// Add custom column headers here 
add_action('woocommerce_admin_order_item_headers', 'my_woocommerce_admin_order_item_headers'); 
function my_woocommerce_admin_order_item_headers() { 
    // set the column name 
    $column_name = 'Test Column'; 

    // display the column name 
    echo '<th>' . $column_name . '</th>'; 
} 

// Add custom column values here 
add_action('woocommerce_admin_order_item_values', 'my_woocommerce_admin_order_item_values', 10, 3); 
function my_woocommerce_admin_order_item_values($_product, $item, $item_id = null) { 
    // get the post meta value from the associated product 
    $value = get_post_meta($_product->post->ID, '_custom_field_name', 1); 

    // display the value 
    echo '<td>' . $value . '</td>'; 
} 

我評論它,所以它應該是足夠清晰,但簡而言之這個代碼添加自定義列,命名爲「測試柱」,並此列將從產品的自定義字段中提取值,稱爲「_custom_field_name」。

+0

謝謝,謝謝,謝謝...,你爲我省了很多次!再次感謝:D – 2014-09-03 14:21:10

+0

這段代碼唯一的問題是,它拉取產品的當前元值......而不是在結帳期間(可能)捕獲的元值。 – Garconis 2017-01-05 15:08:59

相關問題