I am working with WC for the first time and I am chasing my tail with this one.
In “Orders” page where customer’s can see all the purchases they’ve made the array shows some basic info about the order.
I need to also show the image of the product the customer bought.
Orders seems to be custom posts, but how do I get the image product?
I realize the question is too vague. Any pointers would be a big great help.
Orders are custom post types of
shop_order
type. Orders do not have thumbnails themselves, but orders have a list of products that were purchased and each product has the possibility of a thumbnail.You can see in the
order-details.php
template how to get all the items/products associated with any order object…$order->get_items()
This returns an array of data that is stored in separate database tables. With the
$item
variable you can get the original product and you can see in the linked template that the$product
variable that is being sent to theorder-details-item.php
is defined asorder->get_product_from_item( $item )
.Anyway, once you have the
$product
object you can use$product->get_image()
to retrieve the product’s image.As a simplified example, this would show the thumbnails for all the products purchased in order 999.
Nesting this inside of your loop:
Though normally, the
order-details.php
template should have links to an overview of each individual order.