【问题标题】:Add the product thumbnail on Woocommerce Thankyou page在 Woocommerce 感谢页面上添加产品缩略图
【发布时间】:2019-12-11 09:59:21
【问题描述】:

在 woocommerce 中,在收到的订单页面(感谢页面)上,产品图片不会显示在订单商品中。

如何在收到订单页面的订单商品中显示产品图片?
有没有可用的钩子?
还是我必须覆盖模板order/order-details-item.php 文件?

感谢任何帮助。

【问题讨论】:

  • 希望您至少尝试自己编写代码。我建议您通过 Google 或通过搜索 SO 进行一些额外的研究,然后进行尝试。如果您仍然遇到问题,请返回您的代码并在原始问题的正文中说明您尝试过的内容。
  • 谢谢你的帮助,我从昨天开始就在找这个。我已经尝试了很多次,仍然没有成功。

标签: php wordpress image woocommerce orders


【解决方案1】:

要在收到订单页面的订单商品中显示缩略图(谢谢),您将使用:

// 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 文件中。经过测试并且可以工作。

【讨论】:

  • 我尝试修改您的代码以同时考虑订单支付和订单接收端点,但没有让它工作。有什么我想念的吗? if( ! is_wc_endpoint_url('order-pay') || ! is_wc_endpoint_url('order-received') ) return $item_name;
猜你喜欢
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
  • 2021-07-07
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
相关资源
最近更新 更多