从WooCommerce画廊中删除特色图片

Jp *_*ltz 6 php wordpress product image woocommerce

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

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

任何解决此问题的方法,这样我就不会收到错误?

这是我的代码:

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 '';
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

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

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

Loi*_*tec 7

只有2个参数进行woocommerce_single_product_image_thumbnail_html过滤钩子。

所以你必须稍微改变你的代码以避免错误,这样:

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;
}
Run Code Online (Sandbox Code Playgroud)

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。


过滤钩参考woocommerce_single_product_image_thumbnail_html