Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeric/71f60753d0d8d44e64e0d48e0e5123ef to your computer and use it in GitHub Desktop.
Save smeric/71f60753d0d8d44e64e0d48e0e5123ef to your computer and use it in GitHub Desktop.
Overwrite default thumbnails sizes after WooCommerce installation
<?php
add_action( 'after_setup_theme', 'mytheme_woocommerce_set_image_dimensions' );
function mytheme_woocommerce_set_image_dimensions() {
// Do not set sizes multiple times
if ( ! get_option( 'mytheme_shop_image_sizes_set' ) ) {
$catalog = array(
'width' => '768', // px
'height' => '', // px
'crop' => 0 // no-crop
);
$single = array(
'width' => '595', // px
'height' => '', // px
'crop' => 0 // no-crop
);
$thumbnail = array(
'width' => '', // px
'height' => '127', // px
'crop' => 0 // no-crop
);
// 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
// Set "images sizes set" option
add_option( 'mytheme_shop_image_sizes_set', 1 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment