1

In Woocommerce, I am customizing my view order in MyAccount. I already added the Product images with this answer code: Add the product image to Woocommerce my account order view

Now I would like to add the Product SKU to The View order pages but, I don't know how to get it.

Anyone have an Idea?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • If you don't make changes to a stackOverFlow answer code, please just add the link to your question. Anyways when using an existing answer thread you should please always add the link in your question. – LoicTheAztec Nov 06 '18 at 17:48

1 Answers1

1

Replacing your code with the following to display the product SKU in order items:

// Display the product thumbnail in order view pages
add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );
function 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)
        // The thumbnail
        if( $product->get_image_id() > 0 )
            $item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
        // The SKU
        if( $sku = $product->get_sku() )
            $item_name .= '<br><div class="product-sku">' . $sku . '</div>';
    }
    return $item_name;
}

Code goes in function.php file of your active child theme (active theme). It should works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399