0
我需要为订单商品添加自定义列,并在此列中显示特定产品元。 我的意思是像下面的图像, 我无法从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>';
}
我评论它,所以它应该是足够清晰,但简而言之这个代码添加自定义列,命名为“测试柱”,并此列将从产品的自定义字段中提取值,称为“_custom_field_name”。
谢谢,谢谢,谢谢...,你为我省了很多次!再次感谢:D – 2014-09-03 14:21:10
这段代码唯一的问题是,它拉取产品的当前元值......而不是在结帐期间(可能)捕获的元值。 – Garconis 2017-01-05 15:08:59