禁用WooCommerce中的原始图像裁剪 [英] Disable original image crop in WooCommerce

查看:520
本文介绍了禁用WooCommerce中的原始图像裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在woocommerce中禁用原始图像裁剪?

How to disable original image crop in woocommerce?

因为我在裁剪WooCommerce流程时遇到问题:

Because I have a problem with cropping WooCommerce process:

原始图片

裁剪图片:

如何修复此问题,在原始图像中使用,WooCommerce不会调整缩放缩略图的尺寸?

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

推荐答案

转到woocommerce>设置>产品(标签)>显示(子标签)

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

然后在页面底部的产品图片,停用硬裁剪选项和保存更改

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

然后,您需要使用 重新生成缩略图插件

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


  • 安装并激活 重新生成缩略图插件

  • 进入工具菜单,您会看到重新生成缩略图项目页面。

  • 重新生成所有缩略图(这将重新生成WordPress网站的所有缩略图图像。

  • 在WordPress Media中库(在列表视图中),您可以逐个重新生成缩略图。

  • 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

WITH PHP ALTERNATIVE:

有时在某些主题中,设置是硬编码的。所以你可以改变它们此代码段,将其粘贴到您的活动子主题或主题的function.php文件中:

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 );

您可以评论/取消注释代码(或删除部分内容)以满足您的需求。此代码将覆盖WooCommerce设置>产品>显示(产品图像)中的定义选项。

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:
您需要将活动主题切换为另一个,然后切换回激活它。

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...

这篇关于禁用WooCommerce中的原始图像裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆