Mo *_*edi 0 php wordpress wordpress-plugin woocommerce
我需要为订单商品添加自定义列,并在此列中显示特定的产品元数据。我的意思是如下图所示,我找不到woocommerce的任何操作来添加此列!

您可以使用以下代码:
// 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>';
}
Run Code Online (Sandbox Code Playgroud)
我已经对此进行了评论,因此应该足够清楚,但是简而言之,该代码添加了一个名为“ Test Column”的自定义列,该列从产品的自定义字段中提取了值,即“ _custom_field_name”。
| 归档时间: |
|
| 查看次数: |
5027 次 |
| 最近记录: |