用于自定义产品图像缩略图的挂钩 [英] Hook for customizing product image thumbnail

查看:31
本文介绍了用于自定义产品图像缩略图的挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关 woo-commerce 的帮助以覆盖购物车产品图片缩略图.
我正在创建一个插件,用于在详细信息页面中自定义产品,如果我们添加到购物车",它将在购物车页面中使用自定义缩略图进行更新.

I need a help on woo-commerce to override the cart product image thumbnail.
I am creating a plugin for customizing the product in the detail page and if we do "add to cart" it will be updated in the cart page with a customized thumbnail.

如果有任何钩子可用于覆盖图像,请告诉我.

If any hook is available for overriding the image, please let me know.

推荐答案

我也花了很多时间寻找答案,甚至问了一个 Stackoverflow 问题(WooCommerce:使用过滤器/操作挂钩更改产品图片永久链接),现在恰好是重复的(可以在提交我自己的问题之前找不到这个问题).

I've spent many hours searching for the answer also and even asked a Stackoverflow question (WooCommerce: change product image permalink with filter/action hook) which now happens to be duplicate (could not find this question prior to submitting my own).

钩子是woocommerce_cart_item_thumbnail.所以在你的 functions.php 添加

The hook is woocommerce_cart_item_thumbnail. So in your functions.php add

function custom_new_product_image($a) {

    $class = 'attachment-shop_thumbnail wp-post-image'; // Default cart thumbnail class.
    $src = [PATH_TO_YOUR_NEW_IMAGE];

    // Construct your img tag.
    $a = '<img';
    $a .= ' src="' . $src . '"';
    $a .= ' class="' . $class . '"';
    $a .= ' />';

    // Output.
    return $a;

}

add_filter( 'woocommerce_cart_item_thumbnail', 'custom_new_product_image' );

您的缩略图将被替换(如果您想单独更改每个缩略图,则需要进行更多处理).

and your thumbnails will be replaced (more processing needed if you want to change each thumbnail individually).

这篇关于用于自定义产品图像缩略图的挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆