WooCommerce:使用过滤器/动作挂钩更改产品图像永久链接 [英] WooCommerce: change product image permalink with filter/action hook

查看:248
本文介绍了WooCommerce:使用过滤器/动作挂钩更改产品图像永久链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找过滤器/操作挂钩(或任何其他方式)来更改在购物车页面上显示的图像URL作为缩略图。

示例图像: http://jamescollings.co.uk/wp-content/uploads/2014/ 12 / cart-donation-form.png



我发现它是通过 $ _ product-> get_image()方法,但我找不到类似于 $ _ product-> set_image()的任何内容。

解决方案

我找到了答案:
钩子是 woocommerce_cart_item_thumbnail
所以你的 functions.php 添加

  function custom_new_product_image ($ a){

$ class ='attachment-shop_thumbnail wp-post-image'; //默认购物车缩略图类。
$ src = [PATH_TO_YOUR_NEW_IMAGE];

//构造你的img标签。
$ a ='< img';
$ a。='src ='。$ src。'';
$ a。='class ='。$ class。'';
$ a。='/>';

//输出。
返回$ a;

}

add_filter('woocommerce_cart_item_thumbnail','custom_new_product_image');

并且您的缩略图将被替换(如果您想单独更改每个缩略图,则需要更多处理)。 / p>

I am looking for a filter/action hook (or any other way) to change image URL that is displayed on cart page as a thumbnail.
Example image: http://jamescollings.co.uk/wp-content/uploads/2014/12/cart-donation-form.png

I found that it is retrieved via $_product->get_image() method, but I could not find anything similar to $_product->set_image().

解决方案

I have found the answer: 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).

这篇关于WooCommerce:使用过滤器/动作挂钩更改产品图像永久链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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