// hiển thị tên sản phẩm trong trang Order của Woo
// ----- add column to orders that shows which products were ordered -----
function ec_order_items_column($columns) {
$new_columns = array();
foreach($columns as $key=>$column){
$new_columns[$key] = $columns[$key];
if($key === 'order_date') {
$new_columns['ordered_products'] = __('Ordered Products','woo-custom-ec');
}
}
return $new_columns;
}
add_filter('manage_edit-shop_order_columns', 'ec_order_items_column', 99 );
// ----- add data to new column that shows which products were ordered -----
function ec_order_items_column_cnt($column) {
global $the_order; // the global order object
if($column == 'ordered_products') {
// get items from the order global object
$order_items = $the_order->get_items();
if (!is_wp_error($order_items)) {
foreach($order_items as $order_item) {
echo $order_item['quantity'].' × '.$order_item['name'].'
';
}
}
}
}
add_action('manage_shop_order_posts_custom_column', 'ec_order_items_column_cnt', 99);