在最新的 WooCommerce 中,我如何为单个产品图像设置硬裁剪

In Latest WooCommerce How I set Hard crop for Single Product Image

在最新的 WooCommerce 中,没有在 WooCommerce 设置中为单个产品图像启用硬裁剪的选项 area.So 我在 function.php 中编写了一个函数来为单个图像启用硬裁剪。

function ne_theme_setup() {
    add_image_size( 'single-product', 600, 600, true );
}
add_action( 'after_setup_theme', 'ne_theme_setup' );

function custom_product_large_thumbnail_size()    {
    return 'single-product';
}
add_filter('woocommerce_gallery_image_size', 'custom_product_large_thumbnail_size');

此代码有效,但是当我 select 单个产品页面上的变量当时图像发生变化并显示未裁剪版本的图像。

我如何解决这个问题?我想显示 600X600 的单个图像,并针对所有产品变体进行硬裁剪。

最后我为 issue.I 找到了解决方案,在 function.php 中添加了下面的代码。之后我使用重新生成缩略图插件重新生成了所有图像。它对我有用!!

add_filter( 'woocommerce_get_image_size_single', 'my_set_product_img_size' );
add_filter( 'woocommerce_get_image_size_shop_single', 'my_set_product_img_size' );
add_filter( 'woocommerce_get_image_size_woocommerce_single', 'my_set_product_img_size' );
function my_set_product_img_size()
{
    $size = array(
        'width'  => 600,
        'height' => 600,
        'crop'   => 1,
    );
    return $size;
}