订单是自定义帖子类型shop_order
类型。订单本身没有缩略图,但订单有已购买的产品列表,并且每个产品都可能有缩略图。
您可以在order-details.php模板如何获取与任何订单对象关联的所有项目/产品...$order->get_items()
这将返回存储在单独的数据库表中的数据数组。随着$item
变量,您可以获得原始产品,并且您可以在链接的模板中看到$product
正在发送到的变量order-details-item.php
定义为order->get_product_from_item( $item )
.
无论如何,一旦你拥有了$product
你可以使用的对象$product->get_image()
检索产品的图像。
作为一个简化的示例,这将显示订单 999 中购买的所有产品的缩略图。
$order_id = 999;
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item_id => $item ) {
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
echo $product->get_image();
}
将其嵌套在循环内:
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order();
$order->populate( $customer_order );
foreach( $order->get_items() as $item_id => $item ) {
$product' = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
echo $product->get_image();
}
}
虽然正常情况下,order-details.php
模板应包含指向每个订单概述的链接。