问题描述
我正在学习 Woocommerce。我在单个产品页面上,但产品图片出现问题。
我的图片大小是 1000*1000
,但我得到的是 300*300
。
但是当我将鼠标悬停在图像上时,缩放功能完美运行,并且将端到端。
我必须使用什么钩子才能在单页图库滑块中显示产品的实际图像?
我绑定了下面的代码,但仍然没有得到完整的图像。
add_filter( 'woocommerce_get_image_size_gallery_thumbnail',function( $size ) {
return array(
'width' => 900,'height' => 900,'crop' => 1,);
} );
解决方法
以下是如何覆盖 woocommerce-single 图像的示例:
<?php
add_filter( 'woocommerce_get_image_size_single',function( $size ) {
return array(
'width' => 400,'height' => '','crop' => 0,);
} );
在此示例中,我们将宽度设置为 400,将高度设置为“自动”,并且默认情况下我们不会裁剪图像。
如果您想将图像设置为特定大小并裁剪以适合,您可以这样做:
<?php
add_filter( 'woocommerce_get_image_size_single',function( $size ) {
return array(
'width' => 500,'height' => 500,'crop' => 1,);
} );
此代码段会将 woocommerce_thumbnail 图像更改为 500 x 500 像素并裁剪图像。
<?php
add_filter( 'woocommerce_get_image_size_thumbnail',);
} );
上面的代码片段将使单个产品图库图片为 400 x 400 像素。
<?php
add_filter( 'woocommerce_get_image_size_gallery_thumbnail','height' => 400,);
} );