• Resolved plexxa

    (@plexxa)


    I have a question about WooCommerce customer account. Is it possible to insert the product image of the respective purchase in the customer account under “Orders”? I currently only see a placeholder photo.

    thank you!

    Peter

Viewing 7 replies - 1 through 7 (of 7 total)
  • // Display the product thumbnail in order view pages
    add_filter( 'woocommerce_order_item_name', 'ahirwp_display_product_image_in_order_item', 20, 3 );
    function ahirwp_display_product_image_in_order_item( $item_name, $item, $is_visible ) {
        // Targeting view order pages only
        if( is_wc_endpoint_url( 'view-order' ) ) {
            $product   = $item->get_product(); // Get the WC_Product object (from order item)
            $thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
            if( $product->get_image_id() > 0 )
                $item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
        }
        return $item_name;
    
    }

    The following hooked function will do the job (You may need to add some CSS style rules ):

    Thanks

    Thread Starter plexxa

    (@plexxa)

    hi, thanks for your help I mean the “Order page” the code you sent is for the “Order view page”

    I meant like in the picture

    https://ibb.co/vjy88d6

    You can use the following to add product thumbnails on WooCommerce My account > Orders list, beside the order number:

    add_action( 'woocommerce_my_account_my_orders_column_order-number', 'ahirwp_my_account_orders_product_thumbnails', 20, 1 );
    function ahirwp_my_account_orders_product_thumbnails( $order ) {
        echo '<a href="'. wc_get_endpoint_url('view-order') . $order->get_id()  . '/' . '">' . '#' . $order->get_order_number() . '</a>';
    
        // Loop through order items
        foreach( $order->get_items() as $item ) {
            $product   = $item->get_product(); // Get the WC_Product object (from order item)
            $thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
            if( $product->get_image_id() > 0 ) {
                echo '&nbsp;' . $thumbnail;
            }
        }
    }

    Or you can add a new column with the product thumbnails after the order number like:

    add_filter( 'woocommerce_my_account_my_orders_columns', 'ahirwp_filter_woocommerce_my_account_my_orders_columns', 10, 1 );
    function ahirwp_filter_woocommerce_my_account_my_orders_columns( $columns ) {
        $new_column = array( 'order-number' => $columns['order-number']);
        unset($columns['order-number']);
    
        $new_column['order-thumbnails'] = '';
    
        return array_merge($new_column, $columns);
    }
    
    
    add_action( 'woocommerce_my_account_my_orders_column_order-thumbnails', 'ahirwp_filter_woocommerce_my_account_my_orders_column_order', 10, 1 );
    function ahirwp_filter_woocommerce_my_account_my_orders_column_order( $order ) {
        // Loop through order items
        foreach( $order->get_items() as $item ) {
            $product   = $item->get_product(); // Get the WC_Product object (from order item)
            $thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
            if( $product->get_image_id() > 0 ) {
                echo $thumbnail . '&nbsp;' ;
            }
        }
    }

    Code goes in functions.php file of the active child theme (or active theme). Tested and works.

    Thread Starter plexxa

    (@plexxa)

    Thank you! working great!

    Plugin Support Beauty of Code (woo-hc)

    (@beautyofcode)

    Hi @plexxa ,

    Glad to hear that you have managed to achieve your desired results!

    Also, thanks for actively contributing to the WooCommerce community @hemant-ahir ??

    I will go ahead and mark this as resolved then – feel free to?create a new topic?if you need further help.

    Also, if you have a minute, we’d love if you could leave us a review:

    https://www.ads-software.com/support/plugin/woocommerce/reviews/

    Cheers!

    Thread Starter plexxa

    (@plexxa)

    hi, can the product image also be displayed in the download area?

    Plugin Support Beauty of Code (woo-hc)

    (@beautyofcode)

    Hi @plexxa ,

    Kindly note that help custom code is outside our scope of support, and I am unable to find an extension on the WooCommerce.com Marketplace that can help you achieve exactly this.

    You could have a look at the www.ads-software.com plugin repository for a plugin that may help you with this, however we cannot vouch for any third-party plugins.

    Alternatively, for help with custom code, you could hire a developer or ask your customization questions in one of the channels below:

    Hope this points you in the right direction!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Product image – customer account’ is closed to new replies.