duanduji2986 2016-08-07 07:19
浏览 181
已采纳

禁用WooCommerce中的原始图像裁剪

How to disable original image crop in woocommerce?

Because I have a problem with cropping WooCommerce process:

Original Image

enter image description here

Cropped Image:

enter image description here

How can I fix this problem, to have like in original image, no cropping for resized thumbnails by WooCommerce?

  • 写回答

2条回答 默认 最新

  • dongshedan4672 2016-08-07 12:21
    关注

    Go to woocommerce > settings > products (tab) > Display (sub-tab)

    Path to products display

    Then at the bottom of the page, in "Product Images, disable Hard Crop options and save changes:

    products images settings

    Then you will need to regenerate your products images with Regenerate Thumbnails plugin:

    • Install and activate Regenerate Thumbnails plugin.
    • Going In Tools menu you will find a "Regenerate thumbnails" item page.
    • Press Regenerate all thumbnails (this will regenerate all thumbnails images of your WordPress web site.
    • In the WordPress Media Library (in list view), you can regenerate thumbnails one by one.

    WITH PHP ALTERNATIVE:

    Sometimes in some themes, this is settings are hard coded. So you can change them with this code snippet, pasting it in the function.php file of your active child theme or theme:

    function yourtheme_woocommerce_image_dimensions() {
        global $pagenow;
    
        if ( ! isset( $_GET['activated'] ) || $pagenow != 'themes.php' ) {
            return;
        }
        $catalog = array(
            'width'     => '300',   // px
            'height'    => '300',   // px
            'crop'      => 0 // Disabling Hard crop option.
        );
        $single = array(
            'width'     => '150',   // px
            'height'    => '150',   // px
            'crop'      => 0 // Disabling Hard crop option.
        );
        $thumbnail = array(
            'width'     => '90',   // px
            'height'    => '90',   // px
            'crop'      => 0 // Disabling Hard crop option.
        );
        // Image sizes
        update_option( 'shop_catalog_image_size', $catalog );       // Product category thumbs
        update_option( 'shop_single_image_size', $single );      // Single product image
        update_option( 'shop_thumbnail_image_size', $thumbnail );   // Image gallery thumbs
    }
    add_action( 'after_switch_theme', 'yourtheme_woocommerce_image_dimensions', 1 );
    

    You can comment/uncomment the code (or remove some portions) to feet your needs. This code will overwrite define options in WooCommerce settings > Products > Display (Product Images).

    ACTIVATION: You will need to switch your active theme to another and then switch back to activate it.

    You also might need to regenerate product images with Regenerate Thumbnails plugin...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图