从WooCommerce画廊中删除特色图片 [英] Remove featured image from the WooCommerce gallery

查看:83
本文介绍了从WooCommerce画廊中删除特色图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用其他帖子中的建议,但它们不起作用.我不希望在我的产品图像area/image图库中显示特色产品图像,因为我将标题中的特色图像用作背景图像,并且其宽度太大而无法在图库中显示.

I tried using suggestions from other posts but they do not work. I am looking to not show the featured product image in my product images area/image gallery because I am using the featured image in the header as a background image and its too wide to be in the gallery.

到目前为止,这是最接近工作的方法,但是我得到了一个错误.但是,它确实可以满足我的需求.

So far this is the closest thing to working but I get an error. It does however do what I need.

有什么办法解决这个问题,这样我就不会收到错误消息?

Any way to fix this so i do not get the error?

这是我的代码:

add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 3);
function remove_featured_image($html, $attachment_id, $post_id) {
    $featured_image = get_post_thumbnail_id($post_id);
    if ($attachment_id != $featured_image) {
        return $html;
    }
    return '';
}

这是错误:

/home/…/plugins/my-custom-functions/inc/php/functional.php(93)中的remove_featured_image()缺少参数3,第4行的eval()代码

Missing argument 3 for remove_featured_image() in /home/…/plugins/my-custom-functions/inc/php/functional.php(93) : eval()'d code on line 4

警告:/home…/plugins/my-custom-functions/inc/php/functional.php(93)中的remove_featured_image()缺少参数3,第4行上的eval()代码

Warning: Missing argument 3 for remove_featured_image() in /home…/plugins/my-custom-functions/inc/php/functional.php(93) : eval()'d code on line 4

推荐答案

woocommerce_single_product_image_thumbnail_html 过滤器挂钩只有 2个参数.

因此,您必须对代码进行一些更改以避免这种错误:

So you have to change a little bit your code to avoid the error, this way:

add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 2);
function remove_featured_image($html, $attachment_id ) {
    global $post, $product;

    $featured_image = get_post_thumbnail_id( $post->ID );

    if ( $attachment_id == $featured_image )
        $html = '';

    return $html;
}

代码会出现在您活动的子主题(或主题)的function.php文件或任何插件文件中.

过滤器挂钩的引用 :

References for filter hook woocommerce_single_product_image_thumbnail_html:

  • woocommerce模板:
  • woocommerce模板:

这篇关于从WooCommerce画廊中删除特色图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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