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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog