Skip to content

Instantly share code, notes, and snippets.

@dkruchok
Created June 13, 2016 11:01
Show Gist options
  • Save dkruchok/3100e94a835e5c7f42d1ae7e990cf030 to your computer and use it in GitHub Desktop.
Save dkruchok/3100e94a835e5c7f42d1ae7e990cf030 to your computer and use it in GitHub Desktop.
WooCommerce disable/custom croping
add_action( 'after_setup_theme', function () {
// Add image sizes
$shop_thumbnail = wc_get_image_size( 'shop_thumbnail' );
$shop_catalog = wc_get_image_size( 'shop_catalog' );
$shop_single = wc_get_image_size( 'shop_single' );
// In the lines below, true = hard crop; false = proportional
$shop_thumbnail['crop'] = false;
$shop_catalog['crop'] = false;
$shop_single['crop'] = false;
add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] );
add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] );
add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] );
}, 20 );
@dkruchok
Copy link
Author

all of WooCommerce's image sizes are always hard-cropping in WordPress 4.0 / WooCommerce 2.2.2, no matter what; and like you, I can't seem to save one way or the other in the WooCommerce settings page. I wanted always-proporitional cropping, so I added the following to my theme's functions.php; to force hard crop, change one or more of the 'false's to 'true' (and if you change your mind in the future, you'll have to come back and edit this file):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment