How can i add thumbnails to search results in the Add Product modal (Woocommerce Admin)?

Viewed 47

enter image description here

I'm trying to update the functionality of the search in the Add Products modal (when creating a new order in the WooCommerce Admin area) so that the thumbnail for each product in the search results is also displayed.

How would I go about doing this ? Is there an existing function I can hook into ?

1 Answers

You can use the following snippet, but you'd need to add some styling

add_filter('woocommerce_json_search_found_products', 'test_function_products_image');

function test_function_products_image($products){
    foreach($products as $key => $name){
        $product = wc_get_product($key);
        $src = wp_get_attachment_image_src( $product->get_image_id(), 'thumbnail' )[0];
        if($src){
            $image = '<img class="list-image" src="'. $src . '">';
            $products[$key] = $image . $products[$key];
        }
    }
    return $products;
}
Related