admin管理员组

文章数量:1122846

I'm converting a site across to wordpress that is heavy on imagery. With the fact the products are art based the original sizes have little to no continuity. Now on the product page itself this isn't an issue but in woocommerce the catalog mode is thumbnail sizing is all over the place so alignment looks horrible. Complicating the matter is one of the categories products are more shaped like a door being rather tall by comparison so setting a standard one size for all doesn't work.

Were it is just the thumbs in catalog mode I need to clean up what is the best way to address that with existing images. It is easy to standardize moving forward to address this when taking photos but need a solution to port without manually doing it for hundreds of products.

I'm converting a site across to wordpress that is heavy on imagery. With the fact the products are art based the original sizes have little to no continuity. Now on the product page itself this isn't an issue but in woocommerce the catalog mode is thumbnail sizing is all over the place so alignment looks horrible. Complicating the matter is one of the categories products are more shaped like a door being rather tall by comparison so setting a standard one size for all doesn't work.

Were it is just the thumbs in catalog mode I need to clean up what is the best way to address that with existing images. It is easy to standardize moving forward to address this when taking photos but need a solution to port without manually doing it for hundreds of products.

Share Improve this question asked Jun 27, 2018 at 14:59 rnbrnb 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Set the product thumbnail size and enforce whichever form of cropping gives you the consistency you're looking for. This will let you set whatever width you prefer:

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

Next, to affect cropping:

Crop square: update_option( 'woocommerce_thumbnail_cropping', '1:1' );

Don't crop at all: update_option( 'woocommerce_thumbnail_cropping', 'uncropped' );

Or crop to custom ratio:

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

Then, use a plugin that regenerates all thumbnails - this will regenerate every image size for all the existing images.

本文标签: woocommerce offtopicProduct thumbnail size in catalog