The question:
I would like to output the Product Short Description beneath the product name inside the order items table inside WooCommerce emails. I think I know where to place code inside the email template file, but I don’t know how to access the description of an item. I don’t see any mechanism to retrieve it. What do I need to do to echo out the field?
Thanks in advance!
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
I finally tried using var_dump()
on $item
and $_product
, which are both used in the email-order-items.php
template. $_product
revealed a post
object, which itself has a post_excerpt
property, which looks like it holds the contents of the “Product Short Description” from the WooCommerce product form.
So, to add the description beneath the item name, I added this to my code:
echo '<br/>' . $_product->post->post_excerpt;
Voilà! The short description appears in the email!
Hope this helps someone else! Took me a couple hours of frustration to get it.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0