Automattic\WooCommerce\Blocks\BlockTypes

AllProducts::get_store_thumbnail_aspect_ratioprivateWC 1.0

Get the store thumbnail aspect ratio from WooCommerce Customizer settings. This method is a copy from the one in ProductImage.php.

Method of the class: AllProducts{}

No Hooks.

Returns

string|null. CSS aspect ratio value (e.g. "1/1", "4/3"), or null when uncropped.

Usage

// private - for code of main (parent) class only
$result = $this->get_store_thumbnail_aspect_ratio();

AllProducts::get_store_thumbnail_aspect_ratio() code WC 11.0.1

private function get_store_thumbnail_aspect_ratio() {
	$cropping = get_option( 'woocommerce_thumbnail_cropping', '1:1' );

	if ( 'uncropped' === $cropping ) {
		return null;
	}

	if ( 'custom' === $cropping ) {
		$width  = max( 1, (float) get_option( 'woocommerce_thumbnail_cropping_custom_width', '4' ) );
		$height = max( 1, (float) get_option( 'woocommerce_thumbnail_cropping_custom_height', '3' ) );

		return $width . '/' . $height;
	}

	return str_replace( ':', '/', $cropping );
}