Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.