I’m trying to improve WooCommerce’s Order overview screen, I would like to add an column with ordered products.
So I can see for example this columns:
Order #, Order Total, Ordered products, Address, Notes, Action
We have already found some code on the internet to add an column with products, but it is missing products SKU. What I can see currently:
- 1x ProductnameA
- 3x ProductnameC
What I would like to see:
- 1x ARM-002 (ProductnameA)
- 3x ARM-008 (ProductnameC)
I have used this code for adding the column:
add_filter('manage_edit-shop_order_columns', 'add_ordered_products_column', 11);
function add_ordered_products_column($columns) {
$columns['order_products'] = "Ordered products";
return $columns;
}
And this one for adding the content of the column:
add_action( 'manage_shop_order_posts_custom_column' , 'add_ordered_products_column_content', 11, 2 );
function add_ordered_products_column_content( $column ) {
global $post, $woocommerce, $the_order;
switch ( $column ) {
case 'order_products' :
$terms = $the_order->get_items();
if ( is_array( $terms ) ) {
foreach($terms as $term) {
echo $term['item_meta']['_qty'][0] .' x '. $term['name'] .'<br />';
}
}
else {
_e( 'Unable to get products', 'woocommerce' );
}
break;
}
}
I would like to use something like $term[‘sku’], but that doesn’t work, neither get_sku();.
Anyone who knows a solution for this problem?
First of all if you’re looking for products SKU, replace this line of code:
with this:
If after that something is still wrong, I recommend you to check this code which works for me.
Have you tried with something like
Where
Please note as of Woocommerce 3.0 that this line of code:
no longer displays the qty of the item ordered.
You have to exchange that for this line of code if you’re on Woocommerce 3.0 and higher: