【问题标题】:Add Product Thumbnail to My Account - Recent Orders - Woocommerce将产品缩略图添加到我的帐户 - 最近的订单 - Woocommerce
【发布时间】:2015-09-13 16:27:32
【问题描述】:

我想知道是否有办法将产品缩略图添加到 Woocommerce 前端“我的帐户”中买家的“最近订单”页面。

我一直在努力寻找某种解决方案,但没有运气。

我没有尝试任何方法给你一个代码,只是因为我不知道如何 实际去做吧。

有人能指出我正确的方向吗?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您需要编辑templates/myaccount/my-orders.php。将以下代码添加到您希望显示缩略图的位置。

    <?php 
        // Get a list of all items that belong to the order
        $products = $order->get_items();
    
        // Loop through the items and get the product image
        foreach( $products as $product ) {                  
    
            $product_obj = new WC_Product( $product["product_id"] );
    
            echo $product_obj->get_image();
    
        }
    ?>          
    

    【讨论】:

    • 我很高兴我能帮上忙 :) 编码愉快。
    • @UpendraSharma :如答案中所述,将其添加到您希望缩略图显示的位置,只需确保将其添加到 foreach ( $customer_orders as $customer_order ) { 循环中
    • @AnandShah:我添加了这个,但它只显示缩略图而不是实际图像
    • @UpendraSharma,你可以把图片大小传给get_image,默认是shop_thumbnail,所以如果你需要大图使用echo $product_obj-&gt;get_image( 'large' );
    猜你喜欢
    • 2018-11-28
    • 2021-05-14
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2019-01-24
    • 2019-04-10
    相关资源
    最近更新 更多