How to override admin order item thumbnail in woocommerce

How to override admin order item thumbnail in woocommerce

Sometimes you need to change item thumbnail of product in admin order in woocommerce, this example code shows how you can override item thumbnail in admin order woocommerce. Copy and paste this code in your theme’s function.php

// overwrite thumbnails of product in order in admin
function custom_woocommerce_admin_order_item_thumbnail( $product_get_image_thumbnail_array_title_false, $item_id, $item ) {
    // make filter magic happen here...
    $product_id = $item->get_product_id();
    // check product type here
    $is_upload = get_post_meta( $product_id,'upload_product', true);
	if(is_array($is_upload)){
		// replace image you want to replace here 
		$get_img = get_post_meta( $product_id,'file_upload', true);
		return '<img width="150" height="150" src="'.$get_img.'" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" title="">';
	}
	else{
		$product      = $item->get_product();
		$thumbnail    = $product->get_image( 'thumbnail', array( 'title' => 'image' ));
		return($thumbnail);
	}
}

// add the filter
add_filter( 'woocommerce_admin_order_item_thumbnail', 'custom_woocommerce_admin_order_item_thumbnail', 10, 3 );

Comments

comments

Share