Show Products Purchased On WooCommerce Orders Page
In this post we are adding a products purchased column to the WooCommerce orders page.
1. Adjust as needed and add the following code to your theme's functions.php file.
add_filter( 'manage_edit-shop_order_columns', 'add_wc_order_list_custom_column' );
function add_wc_order_list_custom_column( $columns ) {
$reordered_columns = array();
// Inserting columns to a specific location
foreach( $columns as $key => $column){
$reordered_columns[$key] = $column;
if( $key === 'order_status' ){
// Inserting after "Status" column
$reordered_columns['products_purchased'] = __( 'Products Purchased','woocommerce');
}
}
return $reordered_columns;
}
add_action('manage_shop_order_posts_custom_column', 'display_wc_order_list_custom_column_content', 10, 2);
function display_wc_order_list_custom_column_content( $column, $post_id ){
switch ( $column )
{
case 'products_purchased' :
// Get order object
$order = wc_get_order( $post_id );
// Get order items
$items = $order->get_items();
// Output each item
foreach ( $items as $item_id => $item ) {
echo $item->get_quantity() .' x ' . $item->get_name() .'
';
}
break;
}
}
THANKS FOR READING
Thank you for reading Show Products Purchased On WooCommerce Orders Page. I hope you enjoyed it. You can give me feedback, say hi or yell at me on twitter.com/beuinteractive.