In this tutorial we’ll learn how to add product category name on order page in admin side.
First of all we need to place an order if any haven’t played already.
To place an order follow the following steps.
First of all add a product to cart by clicking on add to cart button.
After that, move to cart by clicking on view cart link.
From cart page click on proceed to checkout button.
After that place order by clicking on place order button.
Now if you go to backend and look into orders under woocommerce tab, you’ll see the newly placed order there.
Now, if you look into order details you’ll see there is no category name listed under.
Now we need to display category name for products here as well.
To do this add the following lines of code at the end of your theme’s functions.php file:
add_action('woocommerce_before_order_itemmeta','woocommerce_before_order_itemmeta',10,3); function woocommerce_before_order_itemmeta($item_id, $item, $product){ echo '<p>'.get_the_term_list($product->id, 'product_cat').'</p>'; }
You can access the functions.php file here:
Save the file by clicking on update file button after placing the above code.
Now if you move to an order from backend again you’ll see category name listed under products in order.
Is it possible disply only subcategories? And if the product have more categories insert comma and space between them?