设置产品缩略图大小并强制执行任何形式的裁剪,以获得所需的一致性。这将允许您设置您喜欢的任何宽度:
<?php
function wpse_307110_override_thumbnail_sizes() {
$theme_support = get_theme_support( \'woocommerce\' );
$theme_support = is_array( $theme_support ) ? $theme_support[0] : array();
// change 150 to whatever width you need
$theme_support[\'thumbnail_image_width\'] = 150;
remove_theme_support( \'woocommerce\' );
add_theme_support( \'woocommerce\', $theme_support );
}
add_action( \'after_setup_theme\', \'wpse_307110_override_thumbnail_sizes\', 10 );
?>
接下来,要影响裁剪:
裁剪方形:update_option( \'woocommerce_thumbnail_cropping\', \'1:1\' );
根本不裁剪:update_option( \'woocommerce_thumbnail_cropping\', \'uncropped\' );
或裁剪与自定义比率:
// set width and height as needed: this creates a 4:3 ratio
// so if width is 150px, height will be 113px (112.5 rounded up)
update_option( \'woocommerce_thumbnail_cropping\', \'custom\' );
update_option( \'woocommerce_thumbnail_cropping_custom_width\', \'4\' );
update_option( \'woocommerce_thumbnail_cropping_custom_height\', \'3\' );
然后,使用重新生成所有缩略图的插件-这将为所有现有图像重新生成每个图像大小。