Add the product thumbnail on Woocommerce Thankyou page - php

In woocommerce, on Order received page (Thankyou page) the product image is not displayed in the order items.
How can I display the product image in order items on Order received page?
Is there a usable hook for that?
Or do I have to override the template order/order-details-item.php file?
Any help is appreciated.

To display the thumbnail image in the order items on Order received page (thankyou), you will use:
// 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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related

Replace the product name by the Sku in the order received page

Using Woocommerce, I would like to add the SKU instead of the product name in the thank you page and order pages like in Order received (thankyou) and Order pay pages.
I use the woocommerce_cart_item_name filter hook like in this previous thread, but it works only My account > View order pages.
I have also tried to use woocommerce_add_order_item_meta filter hook, but it doesn't work.
Can I know the correct complete code to add to function.php to be able to replace the product name by the SKU in Order received (thankyou) and Order pay pages.
To replace the product name by the SKU on Order received, Order pay (and my account Order view) pages, you need to use the following:
add_filter( 'woocommerce_order_item_name', 'display_sku_in_order_item', 20, 3 );
function display_sku_in_order_item( $item_name, $item, $is_visible ) {
if( is_wc_endpoint_url() ) {
$product = $item->get_product();
if( $sku = $product->get_sku() )
$item_name = '' . __( "Product ", "woocommerce") . $sku . '';
}
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
Related: Woocommerce conditional tags reference

Add an icon after product price on Woocommerce archive pages

I am trying to add a custom icon after the product price in Woocommerce for a specific product category on shop page. So I would like to add an icon of a "fast delivery truck" after the price on all products from "FAST SHIPPING" product category.
I would like it to display that like in wish.com web site, like in this screenshot:
This is what I've tried:
add_filter( 'woocommerce_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $instance ) {
if(is_product_category( 'fast-shipping')){
$icon = ' <i class="fas fa-shipping-fast"></i> ';
$price = $icon . $price . $icon;
}
return $price;
}
But It doesn't display anything after the price.
Any help would be much appreciated.
You are using the wrong hook since Woocommerce 3 and there are some errors in your code.
To display an icon after the price on the right for "fast-shipping" product category, two cases:
1) On all Woocommerce archive pages:
add_filter( 'woocommerce_get_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $product ) {
if( has_term( 'fast-shipping', 'product_cat', $product->get_id() ) && ! is_product() ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
2) On a specific Woocommerce product category archive pages:
add_filter( 'woocommerce_get_price_html', 'append_icon_after_product_price', 10, 2 );
function append_icon_after_product_price( $price, $product ) {
if( is_product_category( 'fast-shipping' ) ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Use css before or after belong to the price tag :
fa-shipping-fast:before{
content: url(.....);
width : ....;
height : ....;
....
}

Product title below the thumbnail in Woocommerce email notifications

How to make the text with the name of the product in the woocommerce email be below the product image?
I want the letters to look good.
Updated: If the product image are displayed in your email notifications, you can try the following to display the product title under this image:
add_filter( 'woocommerce_order_item_name', 'product_title_under_thumbnail_emails', 10, 3 );
function product_title_under_thumbnail_emails( $item_name, $item, $is_visible ) {
// Targeting view order pages only
if( is_wc_endpoint_url() )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $product->get_image_id() > 0 && $is_visible )
$item_name = '<br>' . $item_name;
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). It should works.

Add the sku to order items on my account order view pages in Woocommerce

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?
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.

Woocommerce Short_Description in Details Order

I'm creating my new website with Wordpress and Woocommerce. I would like to display the short description in the order detail.
I found this code :
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5);
But that shows me the description in home.
Is there a way to make it appear in the order detail?
It can be done with a custom unction hooked in woocommerce_order_item_name filter hook, this way:
add_filter( 'woocommerce_order_item_name', 'add_single_excerpt_to_order_item', 10, 3 );
function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
$product_id = $item->get_product_id(); // Get the product Id
$excerpt = get_the_excerpt( $product_id ); // Get the short description
return $item_name . '<br><p class="item-description">' . $excerpt ; '</p>';
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works. It will display the short description in Order items below the item name.

Categories