Yann Chabot
Yann Chabot

Reputation: 4869

WooCommerce - How to add an image next to name of product in Order's ''Add Product'' dropdown

can't find an answer to it, pretty sure there must be a way via filters to do this but can't find anything related to it.

I've noticed that it pings admin-ajax.php?term=MyTestQuery&action=woocommerce_json_search_products_and_variations

Is there a way for me to hijack this call and create my own response or something like this?

enter image description here

As you can see on the image there, it doesn't have an image so sometimes for my customer it's hard since there are a lot of products with similar names.

Is there any filter or action I can use to change that?

Upvotes: 1

Views: 301

Answers (1)

mujuonly
mujuonly

Reputation: 11861

add_filter('woocommerce_json_search_found_products', 'woocommerce_json_search_found_products');

function woocommerce_json_search_found_products($products) {
    foreach ($products as $product_id => $product_formatted_name) {

        $image = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), 'single-post-thumbnail');
        $img_src = isset($image) ? $image[0] : '';
        if ('' !== $img_src) {
            $products[$product_id] = $product_formatted_name . "<img width='30' height='30' src='$img_src'/>";
        }
    }
    return $products;
}

Upvotes: 1

Related Questions