如何在添加产品模式(WooCommerce Admin)中添加缩略图以搜索结果?

发布于 2025-02-11 01:32:43 字数 259 浏览 1 评论 0原文

我正在尝试更新添加产品模式中的搜索功能(在WooCommerce管理区域中创建新订单时),以便还显示搜索结果中每个产品的缩略图。

我该怎么做?我可以挂接现有的功能吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2025-02-18 01:32:43

您可以使用以下片段,但是需要添加一些样式

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文