php - WooCommerce:更改图库缩略图的大小

标签 php wordpress woocommerce flexslider

我想将图库缩略图的缩略图大小更改为最大。 60x60 像素。不裁剪它们。

我在 WooCommerce 文档中找到了以下钩子(Hook):

add_filter( 'woocommerce_gallery_thumbnail_size', function( $size ) {
    return array('width' => 60, 'height' => 60, 'crop' => 0, );
} );

但是好像crop这个参数没有作用?! WordPress 也会忽略这个尺寸,并在图库导航中始终显示 WordPress 本身的 150x150px 版本。即使在使用插件重新生成缩略图大小之后。 60x60 版本在服务器上。但它未被 WooCommerce 使用,并且已被裁剪。

我还使用此代码为主题添加 WooCommerce 支持:

function mytheme_add_woocommerce_support() {
    add_theme_support( 'woocommerce', array(
        'thumbnail_image_width'         => 240,
        'single_image_width'            => 450,
        'gallery_thumbnail_image_width' => 60,
    ) );
    add_theme_support( 'wc-product-gallery-slider' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );

当我删除它时,WooCommerce 缩略图大小会被完全忽略。

我做错了什么吗? 它适用于其他图像尺寸,例如:

add_filter( 'woocommerce_get_image_size_thumbnail', function( $size ) {
    return array('width' => 240, 'height' => 240, 'crop' => 0, );
} );

add_filter( 'woocommerce_get_image_size_single', function( $size ) {
    return array('width' => 450, 'height' => 450, 'crop' => 0, );
} );

这些图像有最大。宽度和高度,不裁剪。 但画廊缩略图版本总是被裁剪。

最佳答案

我找到了一个解决方案,我猜是过滤器中的名称错误。

我使用的名称 (woocommerce_gallery_thumbnail_size) 是从文档中复制的,但他的版本似乎是正确的:woocommerce_get_image_size_gallery_thumbnail

Hin 来自这里:https://theme.co/forum/t/woocommerce-product-gallery-thumbnails-cropped/47367/2

这是他们的代码:

// change woocommerce thumbnail image size
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', 'override_woocommerce_image_size_gallery_thumbnail' );
function override_woocommerce_image_size_gallery_thumbnail( $size ) {
    // Gallery thumbnails: proportional, max width 200px
    return array(
        'width'  => 60,
        'height' => 60,
        'crop'   => 0,
    );
}

不幸的是,图库 slider 导航仍然使用 150x150 版本的图像。但这不是这个问题的重点。

关于php - WooCommerce:更改图库缩略图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63206146/

相关文章:

php - Opencart的 $this->config->get ('module_var_name' )

php - Symfony onKernelException 监听器

javascript - 新的 Instagram 强制执行签名请求与签名 header

php - 在 WooCommerce 中显示每个购物车商品的重量

php - 更新帖子元 WordPress

php - 您如何扩展Themosis helpers.php函数?

php - 从 PHP 数组创建 HTML 表

wordpress - nginx 错误 "504 Gateway Timeout"

php - woocommerce 中基于角色的税收

php - 库存 > 单独销售部分下的新 WooCommerce 选项