WooCommerce::add_image_sizes()publicWC 2.3

Add WC Image sizes to WP.

As of 3.3, image sizes can be registered via themes using add_theme_support for woocommerce and defining an array of args. If these are not defined, we will use defaults. This is handled in wc_get_image_size function.

3.3 sizes:

woocommerce_thumbnail - Used in product listings. We assume these work for a 3 column grid layout. woocommerce_single - Used on single product pages for the main image.

Method of the class: WooCommerce{}

No Hooks.

Return

null. Nothing (null).

Usage

$WooCommerce = new WooCommerce();
$WooCommerce->add_image_sizes();

Changelog

Since 2.3 Introduced.

WooCommerce::add_image_sizes() code WC 8.7.0

public function add_image_sizes() {
	$thumbnail         = wc_get_image_size( 'thumbnail' );
	$single            = wc_get_image_size( 'single' );
	$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );

	add_image_size( 'woocommerce_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] );
	add_image_size( 'woocommerce_single', $single['width'], $single['height'], $single['crop'] );
	add_image_size( 'woocommerce_gallery_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] );
}