[英]Show woocommerce product description next to product name in orders deatils page at the backend and make it searchable
[英]Show product's image in “Orders” page - Woocommerce
我是第一次與WC合作,並且正在追逐我的尾巴。
在“訂單”頁面上,客戶可以看到他們已經完成的所有購買交易,其中顯示了有關訂單的一些基本信息。 我還需要顯示客戶購買的產品的圖像。
訂單似乎是自定義帖子,但是如何獲得圖片產品?
我意識到這個問題太模糊了。 任何指針都會有很大的幫助。
訂單是shop_order
類型的自定義過shop_order
類型。 訂單本身沒有縮略圖,但是訂單包含已購買產品的列表,每個產品都有縮略圖的可能性。
您可以在order-details.php
模板中看到如何獲取與任何訂購對象關聯的所有商品/產品... $order->get_items()
這將返回存儲在單獨的數據庫表中的數據數組。 使用$item
變量,您可以獲得原始產品,並且可以在鏈接的模板中看到將發送到order-details-item.php
的$product
變量定義為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
模板應具有指向每個單獨訂單概述的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.