Modify Product Name Display in WooCommerce Orders Panel
How to add product name to woocommerce admin order list;
Display product name in woocommerce orders page;
Woocommerce show product name in order details;
Add product name column to woocommerce orders;
Customize woocommerce order list to show product names;
Woocommerce display product names in admin panel;
Show product names on woocommerce my account orders;
Woocommerce order list add product name column;
How to display product name in woocommerce order summary;
Woocommerce admin orders show product details;
Explanation
Want to see product names directly in your WooCommerce admin orders list? This code snippet will help you do just that by adding a new column to display product names.
- Add a New Column: The code first adds a new column called "Product Names" right after the "Order Total" column in your admin orders list. This makes it easy to see what products are included in each order without having to click through.
- Display Product Names: Once the column is added, the code populates it with the names of the products in each order. It gathers all the items in an order and lists their names, separated by commas.
- My Account Page: Additionally, the code tweaks the order details on the "My Account" page for customers. It appends the product name to each item, making it clearer for customers to see what they've ordered.
This setup is perfect for store owners who want a quick overview of order contents right from the admin panel, and it also enhances the customer experience by providing more detailed order information on their account page.
Code
<?php
// Add a new column to the WooCommerce admin orders list to display product names
add_filter('manage_edit-shop_order_columns', 'wp_dudecom_add_product_name_column');
function wp_dudecom_add_product_name_column($columns) {
$new_columns = array();
foreach ($columns as $column_name => $column_info) {
$new_columns[$column_name] = $column_info;
if ('order_total' === $column_name) {
$new_columns['product_names'] = __('Product Names', 'woocommerce');
}
}
return $new_columns;
}
// Populate the new column with product names
add_action('manage_shop_order_posts_custom_column', 'wp_dudecom_display_product_names_in_orders', 10, 2);
function wp_dudecom_display_product_names_in_orders($column, $post_id) {
if ('product_names' === $column) {
$order = wc_get_order($post_id);
$items = $order->get_items();
$product_names = array();
foreach ($items as $item) {
$product_names[] = $item->get_name();
}
echo implode(', ', $product_names);
}
}
// Add product names to the order details in the My Account page
add_filter('woocommerce_order_item_name', 'wp_dudecom_add_product_names_to_my_account_orders', 10, 2);
function wp_dudecom_add_product_names_to_my_account_orders($item_name, $item) {
$product = $item->get_product();
if ($product) {
$item_name .= ' (' . $product->get_name() . ')';
}
return $item_name;
}
?>
Instructions
File Location: Add the following code to your theme's functions.php
file or a custom plugin file.
Prerequisites:
- Ensure WooCommerce is installed and activated on your WordPress site.
Implementation Steps:
- Access your WordPress admin dashboard.
- Navigate to Appearance > Theme Editor if you are adding the code to
functions.php
. Alternatively, use a code editor if you are adding it to a custom plugin file. - Locate the
functions.php
file in your active theme or open your custom plugin file. - Copy the provided code snippet and paste it at the end of the
functions.php
file or your custom plugin file. - Save the changes.
- Go to WooCommerce > Orders in your WordPress admin panel to verify that the "Product Names" column is now visible and populated with product names for each order.
- Visit the "My Account" page as a customer to ensure product names are appended to order items.
If you encounter any issues or need further customization, consider reaching out to wp-dude.com for expert assistance.