Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product Gallery: Replace the frontend custom placeholder with the cor…
Browse files Browse the repository at this point in the history
…e Woo placeholder (#12086)
  • Loading branch information
danieldudzic authored Dec 7, 2023
1 parent 75a3347 commit 3015b12
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/Utils/ProductGalleryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function get_product_gallery_images( $post_id, $size = 'full', $at
$attributes
);
} else {
$product_image_html = self::get_product_image_placeholder_html( $attributes );
$product_image_html = self::get_product_image_placeholder_html( $size, $attributes, $crop_images );
}

if ( $wrapper_class ) {
Expand Down Expand Up @@ -158,23 +158,24 @@ public static function maybe_generate_intermediate_image( $attachment_id, $size
/**
* Get the product image placeholder HTML.
*
* @param array $attributes Attributes.
* @param string $size Image size.
* @param array $attributes Attributes.
* @param bool $crop_images Whether to crop images.
* @return string
*/
public static function get_product_image_placeholder_html( $attributes = array() ) {
$attributes['src'] = esc_url( plugins_url( 'woocommerce-blocks/images/block-placeholders/product-image-gallery.svg' ) );
$attributes['alt'] = esc_attr__( 'Product Image Placeholder', 'woo-gutenberg-products-block' );

$attributes_string = array_reduce(
array_keys( $attributes ),
function ( $carry, $key ) use ( $attributes ) {
$key = esc_attr( $key );
$value = esc_attr( $attributes[ $key ] );
return $carry . $key . '="' . $value . '" ';
},
''
);
public static function get_product_image_placeholder_html( $size, $attributes, $crop_images ) {
$placeholder_image_id = get_option( 'woocommerce_placeholder_image', 0 );

if ( ! $placeholder_image_id ) {

// Return default fallback WooCommerce placeholder image.
return wc_placeholder_img( array( '', '' ), $attributes );
}

if ( $crop_images ) {
self::maybe_generate_intermediate_image( $placeholder_image_id, self::CROP_IMAGE_SIZE_NAME );
}

return '<img ' . $attributes_string . ' />';
return wp_get_attachment_image( $placeholder_image_id, $size, false, $attributes );
}
}

0 comments on commit 3015b12

Please sign in to comment.