woocommerce_email_editor_gallery_cropped_image_url │ filter-hook │ WC 1.0

Filters the URL of an image inside an email gallery so integrations can serve a server-side-cropped file that honors the block's aspect ratio.

Email can't crop client-side reliably, so returning an already-cropped URL (e.g. an image CDN URL with resize/crop parameters) is the only way to honor the crop in every client. Return the URL unchanged to leave the image uncropped (the renderer then falls back to best-effort CSS cropping).

Usage

add_filter( 'woocommerce_email_editor_gallery_cropped_image_url', 'wp_kama_woocommerce_email_editor_gallery_cropped_image_url_filter', 10, 5 );

/**
 * Function for `woocommerce_email_editor_gallery_cropped_image_url` filter-hook.
 * 
 * @param string $image_url    The original image URL.
 * @param string $aspect_ratio The requested aspect ratio (e.g. "1", "4/3").
 * @param int    $width        Target display width of the image in px (0 if unknown).
 * @param int    $height       Target display height derived from the aspect ratio in px (0 if
 *                             unknown).
 * @param array  $image_attrs  Parsed attributes of the core/image block (id, sizeSlug, ...).
 *
 * @return string
 */
function wp_kama_woocommerce_email_editor_gallery_cropped_image_url_filter( $image_url, $aspect_ratio, $width, $height, $image_attrs ){
	// filter...
	return $image_url;
}
$image_url(string)
The original image URL.
$aspect_ratio(string)
The requested aspect ratio (e.g. "1", "4/3").
$width(int)
Target display width of the image in px (0 if unknown).
$height(int)
Target display height derived from the aspect ratio in px (0 if unknown).
$image_attrs(array)
Parsed attributes of the core/image block (id, sizeSlug, ...).

Where the hook is called

Gallery::apply_aspect_ratio_crop()
woocommerce_email_editor_gallery_cropped_image_url
woocommerce/packages/email-editor/src/Integrations/Core/Renderer/Blocks/class-gallery.php 313
$filtered_url = apply_filters( 'woocommerce_email_editor_gallery_cropped_image_url', $image_url, $aspect_ratio, $width, $height, $image_attrs );

Where the hook is used in WooCommerce

Usage not found.