Automattic\WooCommerce\Blocks\BlockTypes

ProductImage::resolve_aspect_ratio │ private │ WC 1.0

Resolve the aspect ratio for a product image.

Block-level overrides take priority over store thumbnail cropping settings.

Method of the class: ProductImage{}

No Hooks.

Returns

string|null. CSS aspect ratio value, or null when no ratio should be applied.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_aspect_ratio( $attributes );
$attributes(array) (required)
Parsed block attributes.

ProductImage::resolve_aspect_ratio() code WC 11.2.2

private function resolve_aspect_ratio( $attributes ) {
	if ( ! empty( $attributes['style']['dimensions']['aspectRatio'] ) ) {
		return $attributes['style']['dimensions']['aspectRatio'];
	}

	if ( ! empty( $attributes['aspectRatio'] ) ) {
		return $attributes['aspectRatio'];
	}

	// For backwards compatibility, we interpret "thumbnail" as following
	// the store thumbnail cropping settings.
	// "cropped" was used as a synonym for "thumbnail" in the past, but it's now deprecated.
	if ( 'thumbnail' === $attributes['imageSizing'] || 'cropped' === $attributes['imageSizing'] ) {
		return $this->get_store_thumbnail_aspect_ratio();
	}

	return null;
}