在 Woocommerce Thankyou 页面上添加产品缩略图
Add the product thumbnail on Woocommerce Thankyou page
在 woocommerce 中,在收到订单页面(谢谢页面)上,产品图片未显示在订单项目中。
如何在“已收到订单”页面上的订单商品中显示商品图片?
有没有可用的钩子?
或者我是否必须覆盖模板 order/order-details-item.php
文件?
感谢任何帮助。
要在已收到订单页面(谢谢)上显示订单商品的缩略图,您将使用:
// Display the product thumbnail in order received page
add_filter( 'woocommerce_order_item_name', 'order_received_item_thumbnail_image', 10, 3 );
function order_received_item_thumbnail_image( $item_name, $item, $is_visible ) {
// Targeting order received page only
if( ! is_wc_endpoint_url('order-received') ) return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $product->get_image_id() > 0 ){
$product_image = '<span style="float:left;display:block;width:56px;">' . $product->get_image(array(48, 48)) . '</span>';
$item_name = $product_image . $item_name;
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
在 woocommerce 中,在收到订单页面(谢谢页面)上,产品图片未显示在订单项目中。
如何在“已收到订单”页面上的订单商品中显示商品图片?
有没有可用的钩子?
或者我是否必须覆盖模板 order/order-details-item.php
文件?
感谢任何帮助。
要在已收到订单页面(谢谢)上显示订单商品的缩略图,您将使用:
// Display the product thumbnail in order received page
add_filter( 'woocommerce_order_item_name', 'order_received_item_thumbnail_image', 10, 3 );
function order_received_item_thumbnail_image( $item_name, $item, $is_visible ) {
// Targeting order received page only
if( ! is_wc_endpoint_url('order-received') ) return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $product->get_image_id() > 0 ){
$product_image = '<span style="float:left;display:block;width:56px;">' . $product->get_image(array(48, 48)) . '</span>';
$item_name = $product_image . $item_name;
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。