add product thumbnail to checkout page only and include variation name

I want to add the product thumbnail to the review order area of the checkout page in a custom plugin. I want to restrict the apply_filter function so that it only applies to the checkout page, but no matter what I try it also applies it to the cart page.

This is the latest version of what I’ve tried. I can’t figure out why the is_checkout part doesn’t seem to do what I thought it should.

/* add product thumbnail to order review table on checkout page only */
add_filter(‘woocommerce_cart_item_name’, ‘jwf_order_review_thumb’, 20, 2);
function jwf_order_review_thumb($cart_item, $cart_item_key){
global $product;
if (is_checkout()) {
$item_data = $cart_item_key[‘data’];
$post = get_post($item_data->id);
$thumb = get_the_post_thumbnail($item_data->id, array( 32, 50));
echo ‘<div id=”jwf_checkout_thumbnail” style=”float: left; padding-right: 8px”>’ . $thumb . ‘</div>’ ;
}
}

The second part of the problem is that I want to also give the product name (including variations). For this, I’m starting with something like this:

add_filter( ‘woocommerce_cart_item_name’, ‘cart_variation_description’, 20, 3);
function cart_variation_description( $name, $cart_item, $cart_item_key ) {
$product_item = $cart_item[‘data’];
if(!empty($product_item) && $product_item->is_type( ‘variation’ ) ) {
return $name;
} else
return $name;
}

What I’d ultimately like to do is combine these two into a single filter that:

determines if the page is the checkout page, then
a. if it is checkout: return both $thumb and $name
b. if it isn’t checkout: return only $name

I’ve tried several times to combine these, but am failing miserably. Any help would be much appreciated! Some of the code I have here comes from other sources, so tips/examples of how to clean it up, if needed, would be helpful too. Thanks in advance.

Read more here:: add product thumbnail to checkout page only and include variation name

Leave a Reply

Your email address will not be published. Required fields are marked *